I work in the Oil & Gas industry.

I have been trying to build a ts forecasting model with covariates, and the model R code is as follows:

#Getting R libraries:

#Create a time series object:
myts <- ts(dataset, start = c(2005,1), end = c(2019,12), frequency = 12)

#Illustrate out of sample forecasting with covariates, splitting the data:
train <- window(myts, end = c(2018,12))
test <- window(myts, start = c(2019,1))

#Fitting the time series forecasting model:
covariates <- c("Income","Prices","Sites","Vehicles")
fit <- auto.arima(train[,"Volumes"], xreg = train[,covariates])

#Forecasting from test data:
mytsfcast <- forecast(fit, h = 6*12, xreg = test[,covariates])


However, I have been trying to forecast the retail volume sales 12,24,36, etc months out. The model only generates the following result:

Model fit results:

Please may I ask that you kindly advise on how I can get my model to forecast beyond end = c(2019,12). I am missing something?

  • $\begingroup$ Hi Stephen. Thanks for the reply. I doubt a smaller h parameter would work as I added the parameter only today. I will give it a try but a model with the xreg argument always ignores the h parameter. $\endgroup$
    – Greaves
    Commented Jan 13, 2020 at 16:18

1 Answer 1


I have not been able to reproduce the blank model fit results. But, I know that the forecast function will only forecast up to known xreg inputs. For instance, your test period starts at 1/2019 and ends 12/2019 (12 periods) however you're attempting to forecast 72 periods. Try setting the h parameter in the forecast function equal to 12 and see if you get the same result.

To get around this problem in the past, I have forecasted the xreg series into the future (in your case an additional 60 periods for each of the four xreg variables). You'll then need to add these 60 periods to the end of the test set for each respective variable.

  • $\begingroup$ Thank you very much for your much needed assistance on this. I certainly will do that. But, are you saying then that once I run the four forecasts 60 periods out beyond 12/2019, I need to copy the resulting forecast data table and add it to the original data set which contains "Volumes", the y-variable I am forecasting? Is there a R code I could use to embed the forecasts into the model rather than manually adding the forecast data into the original data set? Your reply to this is much much appreciated. $\endgroup$
    – Greaves
    Commented Jan 13, 2020 at 16:38
  • $\begingroup$ If I understand the suggestion, I should add the forecast xreg data table to the original data set (and the original data set does include the test set). Please confirm. Thanks once again fellow scientists. $\endgroup$
    – Greaves
    Commented Jan 13, 2020 at 16:45
  • $\begingroup$ There may be way to embed the xreg forecasts into the "Volumes" forecast, but that's beyond my understanding of R programming. To your question, yes that's what I am suggesting. Generate forecasts for the 4 variables included as xreg inputs, and include them with your original data table. Note: you will have to adjust the windows in your original code to reflect the new time windows. $\endgroup$ Commented Jan 13, 2020 at 17:58
  • $\begingroup$ @Greaves as a more general comment. Look here for valuable accuracy measurement techniques. This will help you figure out if the suggested model performs better than more simple (less variables) arima models. $\endgroup$ Commented Jan 13, 2020 at 18:03
  • $\begingroup$ Thanks Danny. I do intend testing the model against simpler ones tomorrow. $\endgroup$
    – Greaves
    Commented Jan 13, 2020 at 19:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.