# Reproducing ARIMA model outside R

I've got an ARIMA(1,1,4) model using external regressor with acceptable output but I'm not able to reproduce it outside the R.

this is the result for the model:

Coefficients:
ar1      ma1     ma2      ma3     ma4  XRegressor[1:39, ]_coeff
0.9500  -1.0202  0.3977  -0.8283  0.6030                0.0084
s.e.  0.1106   0.1999  0.1953   0.2003  0.1526                0.0059

sigma^2 estimated as 9619542:  log likelihood=-360.56
AIC=735.11   AICc=738.84   BIC=746.57


The formula I'm using is as follows:

x(t) = x(t-1)(1+ar1) - ar1*x(t-2) + XRegressor[1:39, ]_coeff*
[xreg(t) - (1+ar1)*xreg(t-1) + ar1*xreg(t-2)] +
ma1*e(t-1) + ma2*e(t-2) + ma3*e(t-3) + ma4*e(t-4)


I'm using residuals as error term in above formula. I could get right result in one step ahead forecast and for further steps, I won't have residuals to substitute in formula. Even by deleting MA part from model, it's not working. Do I miss something here? Can I say by deleting MA part, I'm erasing residual effects?

-
welcome to the website. Please format your post, it is difficult to read. If you could post your data on a publicly accessible website, other users could help you using other software packages. Also, show your exact input syntax. – StasK Feb 29 '12 at 15:48
Thanks and sorry for my mistake, Here is my result for fitted model: Coefficients: ar1 ma1 ma2 ma3 ma4 XRegress 0.9500 -1.0202 0.3977 -0.8283 0.6030 0.0084 s.e. 0.1106 0.1999 0.1953 0.2003 0.1526 0.0059 sigma^2 estimated as 9619542: log likelihood=-360.56 AIC=735.11 AICc=738.84 BIC=746.57 It is difficult for me to provide you my data but my question is somehow general. I need to know how R calculates forecasted results for an ARIMA(1,1,4) model with an external regressor? I provided the formula I use in my first post. Thanks, – Stat1 Feb 29 '12 at 16:41

R uses regression with an ARIMA error, as explained in the help file for arima().
So an ARIMA(1,1,4) model can be written as $$x_t = \beta z_t + n_t$$ where $z_t$ is your regression variable and $n_t$ is an ARIMA(1,1,4) model: $$(n_t - n_{t-1}) = \phi_1 (n_{t-1}-n_{t-2}) + e_t + \theta_1 e_{t-1} + \theta_2 e_{t-2} + \theta_3 e_{t-3} + \theta_4 e_{t-4}.$$
Equivalently, $$x_t = (1+\phi_1)x_{t-1} - \phi_1x_{t-2} + \beta z_t - (1+\phi_1)\beta z_{t-1} + \beta\phi_1 z_{t-2} + e_t + \theta_1 e_{t-1} + \theta_2 e_{t-2} + \theta_3 e_{t-3} + \theta_4 e_{t-4}.$$ So that's the same as your model except that you've omitted the $e_t$ term.
For forecasting, substitute in the residuals if they are available, and set them to zero when they are not. For example, for the two-step forecast, you won't have available $e_{T+2}$ or $e_{T+1}$, but you will have $e_T$, $e_{T-1}$ and $e_{T-2}$, where $T$ is the time of the last observation.