0

In R after calibrating in sample the coefficient for an ARMA model, how can I generate the error which would result of using the same coefficients on another set, out-of-sample, of data ?

Let's say that insamp contains my in sample series, I calibrate an ARMA(5,2) by typing:

    det_fit = arima(insamp , c(5,0,2));

Now I want to compute the error on the outsamp series (I divided arbitrarily the series in two halves insamp and outsamp).

If the model was an AR(5), this is what I did:

    detrended_outsamp_forecast_ts = det_fit$coef["intercept"] + 
    det_fit$coef["ar1"] * c(rep(NA,1), outsamp)  + 
    det_fit$coef["ar2"] * c(rep(NA,2), outsamp) +
    det_fit$coef["ar3"] * c(rep(NA,3), outsamp) +
    det_fit$coef["ar4"] * c(rep(NA,4), outsamp) +
    det_fit$coef["ar5"] * c(rep(NA,5), outsamp);

Which is very long and not generic.

Is there anybody who wrote a function to apply the ARMA coefficients on an arbitrary time-series ?

BlueTrin
  • 9,610
  • 12
  • 49
  • 78
  • 1
    This question will be very difficult to answer unless you do some work to provide a [reproducible](http://stackoverflow.com/q/5963269/324364) example that shows what you've tried so far, and what you've researched to find a solution. – joran Aug 01 '12 at 17:15
  • @joran: good point, is that better ? – BlueTrin Aug 01 '12 at 17:41
  • This may be a dumb question, but have you looked through the documentation in `?arima`? Maybe the See Also section...? – joran Aug 01 '12 at 17:45
  • @joran: I did, there is a function predict, but it is only usable for the next points, it does not allow you to apply on an arbitrary timeseries, I would have thought that I would not be the first one to try to do this ? – BlueTrin Aug 01 '12 at 17:52
  • Probably, I guess. I've never used the `arima` function myself. – joran Aug 01 '12 at 17:54
  • I would have thought it makes sense for any model to calibrate on an in sample and try to see what would happen if you use the same coefficients on an out of sample period ? – BlueTrin Aug 01 '12 at 17:57
  • 2
    Try `Arima` in the **forecast** package. (See the examples) – joran Aug 01 '12 at 18:01

1 Answers1

3
library(forecast)
det_fit <- Arima(insamp, order=c(5,0,2))
new_fit <- Arima(outsamp, model=det_fit)
Rob Hyndman
  • 30,301
  • 7
  • 73
  • 85
  • Many thanks to you Rob and Joran. I would not found out that there was an Arima with capital A – BlueTrin Aug 02 '12 at 09:57
  • by any chance do you know an equivalent package for Garch, I am checking fGarch at the moment but I do not think it has this ability – BlueTrin Aug 02 '12 at 19:27
  • hey I found something that claims to be doing out of sample and it even has a rolling method, http://theaverageinvestor.wordpress.com/tag/garch/ – BlueTrin Aug 05 '12 at 16:17