robjhyndman / forecast

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

NAs with h-step forecasts #324

Closed gabrielcaceres closed 8 years ago

gabrielcaceres commented 8 years ago

Follow up to my comments on #316.

When using h>1 to do h-step forecasts, results are all NA. For example:

fit1 <- auto.arima(WWWusage)
fitted(fit1, h=2)    # all NAs

fit2 <- ets(WWWusage)
fitted(fit2, h=2)    # all NAs

but using hfitted directly works.

hfitted(fit1, h=2)  # correct
hfitted(fit2, h=2)  # correct

I believe this due to the FUN argument when calling hfitted in the fitted.XXX method. For example, see the following line of fitted.Arima:

return(hfitted(object=object, h=h, FUN=Arima, biasadj=biasadj,  ...))

FUN=Arima should be FUN="Arima" or left as the default of FUN=class(object); the same should apply for all other methods.

Additionally, when the xreg argument is used, getting the fitted values with h>1 fails (regardless of the above issue). See:

library(fpp)
fit <- auto.arima(usconsumption[, 1], xreg=usconsumption[, 2])
fitted(fit, h=2)    # all NAs
hfitted(fit, h=2)  # all NAs
robjhyndman commented 8 years ago

Thanks. First issue now fixed.

mitchelloharawild commented 8 years ago

@robjhyndman The second issue was fixed in #327, the above code appears to work without error now.