tscv: Time series cross-validation

Description Usage Arguments Details Value Author(s) See Also Examples

Description

tsCV computes the forecast errors obtained by applying forecastfunction to subsets of the time series y using a rolling forecast origin.

Usage

1
tsCV(y, forecastfunction, h=1, ...)

Arguments

y

Univariate time series

forecastfunction

Function to return an object of class forecast. Its first argument must be a univariate time series, and it must have an argument h for the forecast horizon.

h

Forecast horizon

...

Other arguments are passed to forecastfunction.

Details

Let y contain the time series y[1:T]. Then forecastfunction is applied successively to the time series y[1:t], for t=1,…,T-h, making predictions f[t+h]. The errors are given by e[t+h] = y[t+h]-f[t+h]. These are returned as a vector, e[1:T]. The first few errors may be missing as it may not be possible to apply forecastfunction to very short time series.

Value

Numerical time series object containing the forecast errors.

Author(s)

Rob J Hyndman

See Also

CV, CVar, residuals.Arima.

Examples

1
2
3
#Fit an AR(2) model to each subset
far2 <- function(x, h){forecast(Arima(x, order=c(2,0,0)), h=h)}
e <- tsCV(lynx, far2, h=1)

pli2016/forecast documentation built on May 25, 2019, 8:22 a.m.