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.
tsACV(
y,
algorithm,
m,
h = 1,
v = 1,
xreg = NULL,
lossFunction = function(y, yhat) { (y - yhat)^2 },
...
)
Univariate time-series object.
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.
Length of the window on which the algorithm should be trained.
Number of predictions made after a single training of the algorithm.
Number of periods by which the estimation window progresses forward once the predictions are generated.
Matrix of exogenous regressors supplied to the algorithm (if applicable).
Loss function used to compute contrasts (defaults to squared error).
Other parameters passed to the algorithm.
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.
# NOT RUN {
set.seed(1)
y <- rnorm(40)
m <- 36
h <- 1
v <- 1
tsACV(y, forecast::Arima, m = m, h = h, v = v)
# }
Run the code above in your browser using DataLab