# Calculation of MA model in R

Trying to manually calculate the fitted values from arima in R in order to understand the model. What I am finding is that even though I have not yet learned to calculate the first p values in a AR(p) or MA(p) model, even when I take values returned from arima the first few fitted values dont seem to match. What am I doing wrong?

R Code:

install.packages("forecast")
library(forecast)

wineindT<-window(wineind, start=c(1987,1), end=c(1994,8))
write.table(wineindT,"clipboard",sep="\t")
mod3<-Arima(wineindT,order=c(0,0,1))
mod3$coef write.table(mod3$coef,"clipboard",sep="\t")
write.table(forecast.Arima(mod3,1)$fitted,"clipboard",sep="\t") forecast.Arima(mod3,1)$fitted
mod3$residuals write.table(mod3$residuals,"clipboard",sep="\t")


Here is an Excel calculation: Given the first residual (from arima) my calculation is off for series value 2 and 3 then is correct.

-
Your results don't particularly surprise me since MA models need to be estimated with maximum likelihood. Since your model uses the lag of a residual, that original data point would not be included in the maximum likelihood optimization, though I can't say for certain about the second point. My shot in the dark guess is that using the residuals in period 3 and on, they back out reasonable residuals for the first two periods that would be consistent with the maximum likelihood estimates. But I would have to look more carefully at the code to know for sure. –  John Jul 18 '12 at 23:33
This is to do with the definition of a residual. The residuals returned by arima() and Arima() are standardized to have constant variance. So these are not exactly the same as the error values that are used to compute the fitted values. The standardization only affects the first few residuals.
By the way, it is simpler to use fitted(mod3) and residuals(mod3) to calculate the fitted values and the residuals then it is to use your method.
Actually, fitted(mod3) returns wineindT - residuals(mod3) which are not actually the true fitted values. But the difference is small and for most purposes it doesn't matter.