robjhyndman / forecast

Forecasting Functions for Time Series and Linear Models
http://pkg.robjhyndman.com/forecast
1.12k stars 342 forks source link

predict not working for some series / models #173

Closed christophsax closed 9 years ago

christophsax commented 9 years ago

I got a strange error when using predict on some models generated withauto.arima. E.g., for some shortened versions of AirPassengers


library(forecast)

# this works fine, predict and forecast giving the same 1 period ahead fct
ap1 <- window(AirPassengers, end = c(1959, 4))
m1 <- auto.arima(ap1)
predict(m1)
forecast(m1)

# forecast works as expected, but predict gives an error
ap2 <- window(AirPassengers, end = c(1959, 3))
m2 <- auto.arima(ap2)
predict(m2)

# Error in array(x, c(length(x), 1L), if (!is.null(names(x))) list(names(x),  : 
#   'data' must be of a vector type, was 'NULL'

forecast(m2)

# it also works for shorter time series
ap3 <- window(AirPassengers, end = c(1957, 12))
m3 <- auto.arima(ap3)
predict(m3)
forecast(m3)

> packageVersion("forecast")
[1] ‘6.1’

> R.version
               _                           
platform       x86_64-apple-darwin13.4.0   
arch           x86_64                      
os             darwin13.4.0                
system         x86_64, darwin13.4.0        
status                                     
major          3                           
minor          2.2                         
year           2015                        
month          08                          
day            14                          
svn rev        69053                       
language       R                           
version.string R version 3.2.2 (2015-08-14)
nickname       Fire Safety                 
robjhyndman commented 9 years ago

predict handles a more limited range of models than forecast. In particular, it does not handle drift terms. Conclusion: use forecast.