robjhyndman / forecast

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

No regressors provided error -- one step forward predictions #845

Closed richards-1227 closed 4 years ago

richards-1227 commented 4 years ago

Rob, I received the same error as in this closed post: https://github.com/robjhyndman/forecast/issues/682

One thing that's not clear to me with your solution is that it has new regressors "xreg=ex" but it doesn't seem to be fitting on new values of the TS object.

Sorry if the following isn't clear -- I'm new both to TS analysis and GitHub so I'm not sure how to copy in code.

My attempt at psuedo-code: y is a 250x1 TS object first 188 for training, remainder for validation X is a matrix of regressors (250x4)

I fit a model:

 fit1 <- Arima(y[1:188], order=c(1,1,0), xreg=X[1:188, ])

Now I want one-step forecasts for obs. 189-250:

forecast(y[189:250], model=fit1, xreg=X[189:250,]) 

produces the No regressors provided error

forecast(Arima(y, order=c(1,1,0), xreg=X) , xreg=X  )$fitted[189:250]

produces output (although I do get a Upper prediction intervals are not finite error) but it's not clear if the predictions are truly "out of sample"

On an somewhat unrelated note, is there any way to use the Arima/forecast commands for non-GLM prediction of the residuals based on inputs? In other words yt = \theta * y{t-1} + \eta_t where \eta_t = f(X) + \epsilon_t where f(X) is some non-linear function estimated by something like RF, etc.

Thanks for any help you can provide. Drew

robjhyndman commented 4 years ago
  1. To get multi-step forecasts of observations 189-250:

    forecast(fit1, xreg=X[189:250,]) 
  2. To get one-step forecasts of observations 189-250, with the model trained only on observations 1-188:

    fit2 <- Arima(y, model=fit1, xreg=X)
    fitted(fit2)[189:250]
  3. No.

richards-1227 commented 4 years ago

Thanks.

So then does my earlier code

forecast(Arima(y, order=c(1,1,0), xreg=X) , xreg=X  )$fitted[189:250]

estimate parameters and predict based on all 250 observations? Is there a way to get rolling parameter estimates? I.e. predict observation 190 based on 1-189, predict obs 191 on 1-190, re-estimating every time?

I thought that was the way it was supposed to work if you didn't have X

forecast(Arima(y , order=c(1,1,0) ) )$fitted[189:250]

would give you rolling predictions. Or am I mistaken?

robjhyndman commented 4 years ago

Yes, that re-estimates the model on all data.

To get rolling fits, use tsCV().

richards-1227 commented 4 years ago

It appears to be working with an appropriate modification of this code: