Multi-step forecasts with re-estimation with ARIMA and xreg

Hello there,
I am using @robjhyndman following approach to model 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),
# 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!


It seems you provided some code, but not libraries used, nor example data....

To help us help you, could you please prepare a reproducible example (reprex) illustrating your issue? Please have a look at this guide, to see how to create one:

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.

Can you not provide example data, or the data plus random noise ?
You might be lucky and find a deep expert here who can look at your code and get a sixth sense for your issue. But most of us mortals on the forum (that solve the majority of the volume of issues here) require at least some representative data that makes the problematic code at least runnable in theory in order to get any traction on issues.

the data is trustworthy and can therefore not be provided. The libraries used are the following:

library(stats, forecast)

I would be really thankful if you have any idea, how to help me.
The regressors are from my point of view the same. And I am trying to provide new data row for the forecasting each time.