I have been working with the forecast package in R a lot, recently. And my question might seem trivial (or not, maybe I'm missing something), but for the life of me I can't seem to find a way to fit an Arima model with exogenous variables (xreg
argument) that has been computed by the auto.arima
function to previously unseen test data.
So, I'm basically trying to do the following:
library(forecast)
fit <- auto.arima(trainingdata, xreg = trainingvariables)
...and then I would like to "apply" the model to new test data, for which I also have new exogenous variables available. I can see the following methods:
fitted(fit)
That returns one-step in-sample forecasts, so, in effect, that's exactly what I want. Except that it's in-sample. However, I would like to calculate one-step out-of-sample forecasts (with new exogenous variables that I have available). Another method:
forecast(fit, xreg = newvariables, h = ...)
That works for exactly one step, but then seems to merely forecast the trainingdata stored in the model fit. But I don't think I can use new testdata here? (So, I can't use this method for testing one-step prediction accuracy.) One more idea:
fit2 <- Arima(testdata, model = fit)
According to the manual, if the model
parameter is used, "this same model is
fitted to [testdata] without re-estimating any parameters". Great, but I don't think I can supply any new exogenous variables, can I?
I really think, I must be missing something simple. Any help would be much appreciated.
auto.arima
, you are fitting regressions with ARMA errors rather than ARIMAX model; see Rob J. Hyndman's blog post "The ARIMAX model muddle". $\endgroup$ – Richard Hardy Jan 27 '16 at 15:03newvariables
may not be ats
or adata.frame
, but we have no way of ascertaining this. $\endgroup$ – S. Kolassa - Reinstate Monica Jan 27 '16 at 15:42