flap {flap} | R Documentation |
Forecast Linear Augmented Projection
Description
Reduces forecast variance by adjusting the forecasts of multivariate time series to be consistent with the forecasts of linear combinations (components) of the series by projecting all forecasts onto the space where the linear constraints are satisfied.
Usage
flap(fc, fc_comp, Phi, res, res_comp, p = seq_len(ncol(fc_comp)))
Arguments
fc |
An |
fc_comp |
An |
Phi |
A |
res |
A |
res_comp |
A |
p |
The number of components to use in the projection. The default is trying all the possible number of components capped at the number provided in the forecast. |
Value
A list of class flap
with each element containing a h
by
m
matrix of projected forecast of the original series for the corresponding
number of components p
.
Examples
# Generate example data
# T = 70, m = 20
train <- matrix(rnorm(70 * 20),ncol = 20)
# Obtain the forecast and the residual of the original series
mdl <- apply(train, 2, forecast::ets)
fc <- vapply(mdl, function(mdl) forecast::forecast(mdl, h=12)$mean,
FUN.VALUE = numeric(12))
res <- vapply(mdl, residuals, FUN.VALUE = numeric(70))
# Obtain components and their forecasts and residuals
pca <- stats::prcomp(train, center = FALSE, scale. = FALSE)
mdl_comp <- apply(pca$x, 2, forecast::ets)
fc_comp <- vapply(mdl_comp, function(mdl) forecast::forecast(mdl, h=12)$mean,
FUN.VALUE = numeric(12))
res_comp <- vapply(mdl_comp, residuals,
FUN.VALUE = numeric(nrow(pca$x)))
Phi <- t(pca$rotation)
# flap!
flap(fc, fc_comp, Phi, res, res_comp)