I have about 100 ARIMA models, where each models the demand of a separate household using the temperature as an exogenous value. I've used the auto.arima from the forecast package on R and used xreg to input the temperature.

Now I changed/simulated several series of temperature values and want to use the new temperature values to recalculate the demand using the previously constructed ARIMA model.

I think I can calculate the values manually by referring to each coefficient value of the model. However, it will be inefficient as I have more than 100 models.

Is there a more efficient way to get this done?

So far my code is

arima_model = 
    xreg = as.matrix(house_data$temp)) 
    # model for demand
temp_auto_arima = auto.arima(house_data$temp) 
    # model for the temperature
new_temperature = simulate(temp_auto_arima) 
    # simulate temperature to get a new series 
  • $\begingroup$ What do you mean by 'I have 100 models'? Did you use 100 different models on the same data? $\endgroup$ Apr 29 at 12:42
  • $\begingroup$ "...want to use the new temperature values to recalculate the demand..." You changed the temperature (the regressor) to recalculate the demand. This is unclear to me. How do you calculate the demand? Isn't the demand a given/observed variable that you do not calculate. Or are you talking about making predictions for some other situation? $\endgroup$ Apr 29 at 12:44
  • $\begingroup$ @SextusEmpiricus I have 100 models each for a separate household $\endgroup$ May 2 at 1:02
  • $\begingroup$ I want to simulate the demand value based on the temperature change (and the already constructed ARIMA model) $\endgroup$ May 2 at 1:03
  • $\begingroup$ What do you mean by inefficient? Are you referring to a way to tell simulate (from the forecast package?) new xreg values? $\endgroup$ May 2 at 6:10

1 Answer 1


You can use simulate(arima_model, xreg = new_x) with a the parameter xreg to simulate a time series with a different regressor vector or matrix.

Below is an example

enter image description here

### generate data
t = c(1:1000)
x = sin(t/1000*2*pi*3)
noise = arima.sim(n = 1000, list(ar = c(0.2,-0.5), ma = c(1,0.5)),
                  sd = 0.1)

### plot time series
demand = x + noise
     main = "black: original model \n red: simulate(mod, xreg = new_x)")

### model time series and plot newly generated series
arima_model  = auto.arima(y, xreg = x)
new_x = sin(t/1000*2*pi*3+pi)
points(t,simulate(arima_model , xreg = new_x), col = 2)
  • $\begingroup$ @Thusitha Was this the issue? Or do you not want to change the noise in the newly simulated demand time series and only change the time but keep the same arima noise? $\endgroup$ May 2 at 7:21
  • $\begingroup$ Thank for the answer. However, what I want to do is instead of simulating the demand arima model, recalculate the demand values using the model with simulated temperature $\endgroup$ May 2 at 7:43
  • $\begingroup$ I don't want to simulate the demand. I simulate the temperature and want to use that temperature to calculate the demand using the already constructed ARIMA model $\endgroup$ May 2 at 7:46
  • $\begingroup$ @ThusithaThilinaDayaratne the model is not recalculated, with simulate you use the already constructed arima model (the estimated parameters). Only the particular realization of the noise terms are recomputed/resimulated. Is that what you mean by 'I don't want to simulate'? $\endgroup$ May 2 at 8:09
  • $\begingroup$ @ThusithaThilinaDayaratne if you show the manual method then it becomes clear what you want to do. $\endgroup$ May 2 at 8:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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