0
$\begingroup$

I'm trying to understand how the rolling forecast example below from Rob Hyndman's blog works. In the final line of the for loop, is fc forecasting horizons into the future beyond the end of test? Or is fc meant to be a forecasted version of test, that could be compared to check for accuracy?

My own goal is to create something similar that would train a model and forecast it several horizons in to the future.

Code:

library("fpp")
library("forecast")

##Multi-step forecasts without re-estimation

h <- 5
train <- window(hsales,end=1989.99)
test <- window(hsales,start=1990)
n <- length(test) - h + 1
fit <- auto.arima(train)
fc <- ts(numeric(n), start=1990+(h-1)/12, freq=12)
for(i in 1:n)
{  
  x <- window(hsales, end=1989.99 + (i-1)/12)
  refit <- Arima(x, model=fit)
  fc[i] <- forecast(refit, h=h)$mean[h]
}
$\endgroup$
1
$\begingroup$

Note that n <- length(test) - h +1. So the in the last iteration of the loop, the last h values of test will be forecasted.

The rolling forecast means that you simply refit the model with new observations, i.e. you increase your sample size in each iteration. There is also a variant of rolling fixed-window forecasting where the window length is fixed; you drop the same number of observations from the beginning of the sample as the number of observations you are adding to the end of the sample.

$\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.