50% off: Unlimited data and AI learning.
The Learning Leader's Guide to AI Literacy

forecast (version 8.1)

tsCV: Time series cross-validation

Description

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

Usage

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.

Value

Numerical time series object containing the forecast errors.

Details

Let y contain the time series y1,,yT. Then forecastfunction is applied successively to the time series y1,,yt, for t=1,,Th, making predictions y^t+h|t. The errors are given by et+h=yt+hy^t+h|t. These are returned as a vector, e1,,eT. The first few errors may be missing as it may not be possible to apply forecastfunction to very short time series.

See Also

CV, CVar, residuals.Arima.

Examples

Run this code
# NOT RUN {
#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)

# }

Run the code above in your browser using DataLab