I’m trying to estimate the out-of sample forecast of an ARIMA model, I tried the code below, but it totally doesn’t work!

`for(i in 1:83) { mod[i] <- arima(window(betahat[,1], start=1, end=109+i),order=c(1,0,0),include.mean=TRUE) pre[i] <- predict(mod[i],12) error[i] <- pre[i]$pred[12]-betahat[(109+i+12),1] } `

the data are taken monthly and I divided the data into 2 subsets, the first composed by 109 obs and the second by 83 observations. From the code I would like to obtain the error for each 12 month forecast, so about 59 errors. In the code I probably have to add an if , the argument in [109+i+12] has to be lower than 192, but it’s not the problem.

I don’t know how to obtain each error, I would like that the outcome of the loop is the list of all the errors.

I would appreciate any suggestions.

**Contents**hide

#### Best Answer

In the future it would help if you provided error messages, etc., but for this problem it's easy enough to fix anyway. Just some comments before the code:

1) You don't have to subscript the model or predictions.

2) In the code below, `betahat`

is a vector, not a matrix. Your `betahat`

might also be a vector, which would have caused errors in your run (hence the value of providing the error messages!)

3) Make your for-loop indices correct!

Here you go:

`betahat <- rnorm(192) error <- rep(0,71) for (i in 1:71) { mod <- arima(window(betahat, start=1, end=109+i),order=c(1,0,0),include.mean=TRUE) pre <- predict(mod,12) error[i] <- pre$pred[12]-betahat[109+i+12] } `

### Similar Posts:

- Solved – How to build a function with the result of auto.arima in R
- Solved – How to build a function with the result of auto.arima in R
- Solved – Selecting ARIMA Order using Rolling Forecast
- Solved – Are rolling forecasts more accurate that full-sample forecasts
- Solved – Constructing Deterministic Trend and AR(1) and Forecasting in R