Search code examples
rtime-seriesforecastingarima

How do you forecast ARIMA with multiple regressors?


The complete R data and code for my question is here: https://pastebin.com/QtG6A7ZX.

I am new to R and still a beginner when it comes to time series analysis, so please forgive my ignorance.

I am attempting to model and forecast some enrollment data with 2 dummy-coded regressors. I have already used auto.arima to fit the model:

model <- auto.arima(enroll, xreg=x)

Before I forecast with this model, I am attempting to test its accuracy by selecting only a part of the time series (1:102 instead of 1:112), and likewise, a partial list of regressors.

Based on auto.arima, I fit the partial model as follows:

model_par <-arima((enroll_partial), c(1, 1, 1),seasonal = list(order = c(1, 0, 0), period = 5), xreg=x_par)

I have tried three different ways to forecast and get essentially the same error:

fcast_par <- forecast(model_par, h=10) #error fcast_par <- forecast(model_par, h=10, xreg=x_par) #error fcast_par <- forecast(model_par, h=10, xreg=forecast(x_par,h=10)) #error

'xreg' and 'newxreg' have different numbers of columns

I have tested using auto.arima with the partial data. That works, but gives me a different model and, although I specified 10 predictions, I get over 50:

model_par2 <- auto.arima(enroll_partial, xreg=x_par) fcast_par <- forecast(model_par2, h=12, xreg=x_par) fcast_par

So, my main question is, how do I specify an exact model and predict using more than 1 regressor given my data (see Paste Bin link above)?


Solution

  • The forecast() function is from the forecast package, and works with model functions that are from that package. This is why it is possible to produce forecasts from auto.arima() using forecast(model_par2,xreg=x_fcst).

    The arima() function comes from the stats package, and so there are no guarantees that it would work with forecast(). To specify your own ARIMA model, you can use the Arima() function, which behaves very similarly to arima(), but you will be able to produce forecasts from it using forecast(model_par2,xreg=x_fcst).