[R] predict a MA timeseries

Rolf Turner rolf.turner at xtra.co.nz
Tue May 24 00:03:29 CEST 2011


On 24/05/11 01:24, user84 wrote:
> Hi,
> could anyone tell me how predict() predicts the new value(s), of a MA(1)
> arima-modell.
> its really easy to make it with an AR(1), knowing the last term, but how can
> i or R know the last error?

I think what you're asking here is this:

     Suppose X_t = a_t + theta * a_{t-1} where {a_t} is ``white noise''.
     If you have observed X_1, ..., X_n, the ``prediction'' of X_{n+1}
     is theta * a_n, since E(a_{n+1}) = 0.

     But how do you get a_n?  Recursively.

     Set a_0 = 0 (its expected value).  This gives a_1 = X_1.
     Then you can get a_2 = X_2 - theta*a_1.

     Repeat until you get up to a_n.

This is all a bit naive, and there are traps and problems that
are avoided by more sophisticated procedures, I believed.

A simple answer to the ``how to'' bit, is:  Use predict.Arima().

If you want to know what's actually going on in the software that
makes this prediction .... that's a bit harder.  I think that reading a
basic introductory time series book might help.  Jonathan Cryer's
``Time Series Analysis'' (out of print but available from ABE Books)
is pretty good, and quite gentle.  I suspect that the newer ``Time
Series Analysis with Applications in R'' by Cryer and Chan would also
be good, but I haven't read it.  For something a bit deeper and
more mathematical, Brockwell and Davis (``Time Series:  Theory
and Methods'') is to my mind the gold standard.
> It would also help if somebody could tell me how to find the "open" source
> of the function predict().

Note that ``predict()'' is generic, with many ``methods''.  You are
really interested in the predict.Arima() method as I indicated above.

You can get started by executing:

     stats:::predict.Arima

But that will lead you to KalmanForecast() which will lead you into C code.
You can look at *that* by downloading the source of R from CRAN and
digging around in the appropriate "src" subdirectories --- but figuring
out what's actually going on is likely to be a ***very*** daunting task.
I wouldn't want to try it myself!
> Thanks and sorry for my poor english.

No need to apologize.  Your English is better than my Deutsch.
(The ``.at'' address *does* mean ``Austria'', nicht wahr?)

HTH

     cheers,

         Rolf Turner



More information about the R-help mailing list