# Recalculate fitted values/Simulate of an Arima model with different xreg values

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 =
auto.arima(sqrt(house_data$demand), 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

• What do you mean by 'I have 100 models'? Did you use 100 different models on the same data? Apr 29 at 12:42
• "...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? Apr 29 at 12:44
• @SextusEmpiricus I have 100 models each for a separate household May 2 at 1:02
• I want to simulate the demand value based on the temperature change (and the already constructed ARIMA model) May 2 at 1:03
• What do you mean by inefficient? Are you referring to a way to tell simulate (from the forecast package?) new xreg values? May 2 at 6:10

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

### generate data
set.seed(1)
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
plot(t,demand,
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)
mod

• @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? May 2 at 7:21
• 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 May 2 at 7:43
• 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 May 2 at 7:46
• @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'? May 2 at 8:09
• @ThusithaThilinaDayaratne if you show the manual method then it becomes clear what you want to do. May 2 at 8:13