tsACV {ACV}R Documentation

Perform time-series cross-validation

Description

Function tsACV() computes contrasts between forecasts produced by a given algorithm and the original time-series on which the algorithm is trained. This can then be used to estimate the loss of the algorithm. Unlike the similar tsCV() function from the 'forecast' package, tsACV() also records in-sample contrasts as these can be leveraged to produce more accurate out-of-sample loss estimates.

Usage

tsACV(
  y,
  algorithm,
  m,
  h = 1,
  v = 1,
  xreg = NULL,
  lossFunction = function(y, yhat) {     (y - yhat)^2 },
  ...
)

Arguments

y

Univariate time-series object.

algorithm

Algorithm which is to be applied to the time-series. The object which the algorithm produces should respond to fitted and forecast methods. Alternatively in the case of more complex custom algorithms, the algorithm may be a function which takes named arguments ⁠("yInSample", "yOutSample", "h")⁠ or ⁠("yInSample", "yOutSample", "h", "xregInSample", "xregOutSample")⁠ as inputs and produces a list with named elements ⁠("yhatInSample", "yhatOutSample")⁠ containing vectors of in-sample and out-of-sample forecasts.

m

Length of the window on which the algorithm should be trained.

h

Number of predictions made after a single training of the algorithm.

v

Number of periods by which the estimation window progresses forward once the predictions are generated.

xreg

Matrix of exogenous regressors supplied to the algorithm (if applicable).

lossFunction

Loss function used to compute contrasts (defaults to squared error).

...

Other parameters passed to the algorithm.

Value

Matrix of computed contrasts Phi. Each row corresponds to a particular period of the y time-series and each column corresponds to a particular location of the training window.

Examples

set.seed(1)
y <- rnorm(40)
m <- 36
h <- 1
v <- 1
tsACV(y, forecast::Arima, m = m, h = h, v = v)


[Package ACV version 1.0.2 Index]