Hello there,
I am using @robjhyndman following approach to model rolling forecasts:
https://robjhyndman.com/hyndsight/rolling-forecasts/
This works fine with the provided documentation on ARIMA models. Now I want to include regressors. Taking a look at the comments, one person tried this already but following the same approach, I get an error. Attached you can find my code (as shown in the link):
# Matrix of external factors for regression model (train & test data)
abc <- as.matrix(external_data.ccf_forecast[,c("F19","F45","F46","F50")])
external_data.ccf_test <- window(external_data.ccf_forecast,
start = c(2019, 1),
end = c(2019, 52),
frequency=52)
# Matrix of external test data
def <- as.matrix(external_data.ccf_test[,c("F19","F45","F46","F50")])
#One-step ahead (for a start, later to be increased)
h <- 1
#specify length to forecast
n <- length(test) - h + 1
# create empty matrix
mlr.arima_mat <- matrix(0, nrow = n, ncol = h)
# loop
for (i in 1:n)
{
x <- window(ts, end=c(2018, 52) + (i-1)/52)
xregs <- window(abc, end = c(2018, 52) + (i - 1) / 52)
refit.arima <- auto.arima(x, xreg=xregs)
mlr.arima_mat[i,] <- forecast(refit.arima, xreg=def[i,])$mean
}
Unfortunately, this results in the following errors message:
Error in forecast.forecast_ARIMA(refit.arima, xreg = def[i, ]) :
Number of regressors does not match fitted model
I followed the same procedure, just added the regressors and cannot really figure out what to change to get the results I want. Thanks for help!