1
$\begingroup$

I have been looking for a function that can make recursive window out-of-sample forecasts, but seems there is none. So I'm thinking about about making a function that can be used for recursive window forecasting in an ARIMA model. However I know little about programming, so I'm seeking for help.

What I want to do is use the function forecast.Arima (forecast package) to predict future values in a expanding window. Suppose 20 years is the initial window, and I expand the window by 1 year on each iteration until it is of size 30 years. More specifically, use 20 years data to predict one value, use 21 years data to predict the next value, etc.

$\endgroup$
2
$\begingroup$

The code below probably fits your need, but I use the forecast package. I simulate a 30-year time series to illustrate.

library(forecast) set.seed(1234) y <- ts(sort(rnorm(30)), start = 1978, frequency = 1) # annual data fcasts <- vector(mode = "list", length = 10L) for (i in 1:10) { # start rolling forecast # start from 1997, every time one more year included win.y <- window(y, end = 1996 + i) fit <- auto.arima(win.y) fcasts[[i]] <- forecast(fit, h = 1) }

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.