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 h by m matrix of base forecasts of the original series to be projected. h is the forecast horizon and m is the total number of series.

fc_comp

An h by p matrix of base forecasts of the components used in the projection. h is the forecast horizon and p is the total number of components.

Phi

A p by m weight matrix mapping the original series into the components such that c_t = \Phi z_t where c_t is the vector of components and z_t is the vector of original series.

res

A T by m (in-sample) forecast residual matrix of the original series.

res_comp

A T by p (in-sample) forecast residual matrix of the components.

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)


[Package flap version 0.1.0 Index]