rolling_origin_eval: Rolling origin forecast evaluation

Description Usage Arguments Details References Examples

View source: R/rolling_origin.R

Description

Rolling origin forecast evaluation, a.k.a. time-series cross validation, of a model or method. Computes errors and prediction of a forecast function applied to a time series according to the rolling origin scheme.

Usage

1
rolling_origin_eval(series, start, forecast_fn, h = 1, ...)

Arguments

series

Univariate time series used for fitting and computing forecast errors.

start

Time point used as the starting point for the rolling origin forecast.

forecast_fn

Function which returns forecasts. Takes a time series as its first argument and has an argument h representing the forecast horizon. Returns a vector of length equal to the given forecast horizon h.

h

Forecast horizon. This function will evaluate all horizons 1 to h.

...

Additional arguments passed to forecast_fn

Details

This method implements the rolling origin forecast evaluation (see e.g. Hyndman and Athanasopoulos, 2018). Returns a list of two matrices (multivariate time series), one containing the errors and one the predictions, where columns represent forecast horizon and rows represent time points.

The method starts with a subset X[1:t] and forecasts X[(t+1):(t+h)] based on this subset. Then forecasts X[(t+2):(t+h+1)] based on X[1:(t+1)] and so on.

References

Hyndman, R.J., & Athanasopoulos, G. (2018) Forecasting: principles and practice, 2nd edition, OTexts: Melbourne, Australia. OTexts.com/fpp2. Accessed on 2019-10-18

Examples

1
2
3
4
5
series <- arima.sim(model=list(ar=c(0.6, -0.4)), n=150)
arma_forecast <- function(x, h) {return(
   forecast(arima(x, order=c(2,0,0)), h=h)$mean
)}
roe.res <- rolling_origin_eval(series, 120, arma_forecast, h=5)

rwigren/TSAutils documentation built on Nov. 5, 2019, 5:10 a.m.