# [R] Forecasting MA model different to manually computation?

Don McKenzie dmck at u.washington.edu
Wed May 22 19:10:51 CEST 2013

```Rui responded to your first question graciously with a very simple
That's about as "manual" as you can be without using pencil and paper.

If you can't understand the source code but want to so that you can
understand how the *residuals* are calculated,  it's best to get some
local help.

On 22-May-13, at 8:41 AM, Neuman Co wrote:

> So I mean: How can I calculate them manually?
>
> 2013/5/22 Neuman Co <neumancohu at gmail.com>:
>> Thanks, but this does not help me, because first of all, I do not
>> know
>> how to look at the source code (just entering fitted() or
>> getAnywhere(fitted()) does not help,
>>
>> second, your solution x-m\$residuals does not be a solution, because
>> then the question is, where do the residuals come from?
>>
>>> Hello,
>>>
>>> Since R is open source, you can look at the source code of
>>> package forecast
>>> to know exactly how it is done. My guess would be
>>>
>>> x - m\$residuals
>>>
>>> Time Series:
>>> Start = 1
>>> End = 3
>>> Frequency = 1
>>> [1] 3.060660 4.387627 3.000000
>>>
>>>
>>> Hope this helps,
>>>
>>>
>>> Em 22-05-2013 15:13, Neuman Co escreveu:
>>>>
>>>> Hi,
>>>> 3 down vote favorite
>>>> 1
>>>>
>>>> I am interested in forecasting a MA model.Therefore I have
>>>> created a
>>>> very simple data set (three variables). I then adapted a MA(1)
>>>> model
>>>> to it. The results are:
>>>>
>>>> x<-c(2,5,3)
>>>> m<-arima(x,order=c(0,0,1))
>>>>
>>>> Series: x
>>>> ARIMA(0,0,1) with non-zero mean
>>>>
>>>> Coefficients:
>>>>            ma1  intercept
>>>>        -1.0000     3.5000
>>>> s.e.   0.8165     0.3163
>>>>
>>>> sigma^2 estimated as 0.5:  log likelihood=-3.91
>>>> AIC=13.82   AICc=-10.18   BIC=11.12
>>>>
>>>> While the MA(1) model looks like this:
>>>>
>>>> X_t=c+a_t+theta*a_{t-1}
>>>>
>>>> and a_t is White Noise.
>>>>
>>>> Now, I look at the fitted values:
>>>>
>>>> library(forecast)
>>>> fitted(m)
>>>> Time Series:
>>>> Start = 1
>>>> End = 3
>>>> Frequency = 1
>>>> [1] 3.060660 4.387627 3.000000
>>>>
>>>> I tried different ways, but I cant find out how the fitted values
>>>> (3.060660, 4.387627 and 3.000000) are calculated.
>>>>
>>>> Any help would be very appreciated.
>>>>
>>>>
>>>>
>>>> --
>>>>
>>>> ______________________________________________
>>>> R-help at r-project.org mailing list
>>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>>> http://www.R-project.org/posting-guide.html
>>>> and provide commented, minimal, self-contained, reproducible code.
>>>>
>>>
>>
>>
>>
>> --
>
>
>
> --
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

Don McKenzie, Research Ecologist
Pacific Wildland Fire Sciences Lab
US Forest Service
phone: 206-732-7824

Affiliate Professor
School of Environmental and Forest Sciences
University of Washington

```