# Build ARIMA model equation with exogenous variable or regressors

I have a ARIMA model with three regressors as follow

> fit_arima.reg
Series: sales.ts
Regression with ARIMA(5,1,3) errors

Coefficients:
ar1      ar2      ar3      ar4      ar5      ma1     ma2
0.1806  -0.7205  -0.2697  -0.3786  -0.4372  -0.8307  0.5047
s.e.  0.0786   0.0521   0.0614   0.0277   0.0469   0.0849  0.0920
ma3  pholid  sholid     temp
-0.1397  0.0413  0.1192  -0.0015
s.e.   0.0662  0.0313  0.0180   0.0015

sigma^2 estimated as 0.02461:  log likelihood=412.15
AIC=-800.3   AICc=-799.96   BIC=-742.11


The data is posted here (only the values of two independent variables are missing) and I also referred four links of previous posts related to this topic. I built the equation, but the fitted values by hand (from equation) and the ones generated by R do not match. I would appreciate your help for the solution. This is what I did:

fitted <-fit_arima.reg$$x - (fit_arima.reg$$coef["pholid"]*xregg$$pholid) - (fit_arima.reg$$coef["sholid"]*xregg$$sholid) - (fit_arima.reg$$coef["temp"]*xregg$temp) detach("package:dplyr", unload=T) library(tsDyn) lag1.fit <- lag(fitted,-1) lag2.fit <- lag(fitted,-2) lag3.fit <- lag(fitted,-3) lag4.fit <- lag(fitted,-4) lag5.fit <- lag(fitted,-5) lag6.fit <- lag(fitted,-6) residuals <- fit_arima.reg$x-fitted # are those the residuals?

lag1.res <- lag(residuals,-1)
lag2.res <- lag(residuals,-2)
lag3.res <- lag(residuals,-3)

fitted_equation <-  fit_arima.reg$$coef["pholid"]*xregg$$pholid+
fit_arima.reg$$coef["sholid"]*xregg$$sholid+
fit_arima.reg$$coef["temp"]*xregg$$temp+
fit_arima.reg$$coef["ar1"]*lag1.fit+ fit_arima.reg$$coef["ar2"]*lag2.fit+
fit_arima.reg$$coef["ar3"]*lag3.fit+ fit_arima.reg$$coef["ar4"]*lag4.fit+
fit_arima.reg$$coef["ar5"]*lag5.fit+ lag1.fit- fit_arima.reg$$coef["ar1"]*lag2.fit-
fit_arima.reg$$coef["ar2"]*lag3.fit- fit_arima.reg$$coef["ar3"]*lag4.fit-
fit_arima.reg$$coef["ar4"]*lag5.fit- fit_arima.reg$$coef["ar5"]*lag6.fit-
fit_arima.reg$$coef["ma1"]*lag1.res- fit_arima.reg$$coef["ma2"]*lag2.res-
fit_arima.reg\$coef["ma3"]*lag3.res

> tail(cbind(fitted_equation,fit_arima.reg$$fitted)) Time Series: Start = c(2019, 210) End = c(2019, 215) Frequency = 365 fitted_equation fit_arima.reg$$fitted
2019.573        3.469460             3.426007
2019.575        3.833233             3.623222
2019.578        3.309229             3.507476
2019.581        3.617242             3.418212
2019.584        3.067797             3.196589
2019.586        3.195247                   NA


Similar to Build SARIMA model equation with exogenous variable or regressors . you have the following equation which leads to this after clearing fractions .. multiplying out etc ...

Note that by ordinary convention the ma coefficients are presented differently than what you have seen with your references BUT the answers would be the same.

The data I used had 200 historical observations BUT that doesn't change the way the coefficients are re-presented in a "regression type form " and without the often ( to some !) confusing polynomials and differencing operators.

• Thank very much for your constant feedback and help! – ChrisGila Sep 9 at 8:35