# Joint forecast with Linear Model and ARMA

This might be a rather trivial question, but I cannot seem to figure out how to do this in R. I have estimated a linear model for my time series, and modeled the residuals of the model using an ARMA model (a MA of order 2), as follows:

Time<-1:length(time_series)
linear_model<-lm(time_series~Time)

ma2_resid<-arima(linear_model\$residuals, order=c(0,0,2))


Now I would like to make forecasts with this 'joint' model, i.e., using both the linear model and the MA(2) model. How can I do this in R? Do I first need to forecast the MA(2) model and then add the formula of the linear model, or can I do this al at once?

• How have you identified the right structure for the x matrix. Since this is time series there may be lags needed and potential delays. There may be anomalous values in y or any of the x's . There may be changes in the model's parameters over time. Have you resolved these issues analytically ? – IrishStat Dec 19 '16 at 22:17
• @IrishStat: Yes, I did check this first. – Vam Dec 20 '16 at 7:18
• If you post your residuals , I might be able to suggest refinements to your model . – IrishStat Dec 20 '16 at 17:47

Estimation
Currently you have a two-step estimation procedure: first fit the linear model, then fit a model for the residuals. A more efficient approach would be to estimate the model jointly. Then you would be able to forecast easier and hypothesis testing would also be more straightforward because appropriate standard errors of the linear model would be readily available (unlike in the two-step approach).
Joint estimation can be done via the arima or forecast::auto.arima functions in R. The former would require you to specify the error structure manually, while the latter would pick the error structure according to some information criterion (AICc by default; alternatively AIC or BIC). You would specify the linear model by including the regressors via the optional argument xreg. E.g.

model=arima(y,oder=c(0,0,2),xreg=X)


where y is the dependent variable and X is your design matrix (the matrix of regressors).

Forecasting from jointly estimated model
Once you have estimated your model, you could apply the predict method onto it to get forecasts. You would have to supply new values of regressors via argument newxreg, while the errors would be forecasted automatically given the estimated model object. E.g.

forecasts=predict(model,newxreg=Xnew)


where Xnew are the new values for the regressors.

Forecasting from model estimated in two steps If you are to forecast from the separately estimated linear model and the error equation, here is how it goes:

1. Forecast for the linear model:
Obtain new values of your independent variables and multiply them to the estimated coefficient from the linear model (model1):
predict(model1,newdata=Xnew)
or
f1=coef(model1)[1]+Xnew%*%coef(model1)[-1]
(the [1] and [-1] deal with the intercept if it is not included within Xnew).
2. Forecast for the error equation:
Use the predict function for the estimated MA (or ARMA) model (model2):
f2=predict(model2)
3. Add the two forecasts together:
forecast=f1+f2