Package 'flap'

Title: Forecast Linear Augmented Projection
Description: The Forecast Linear Augmented Projection (flap) method 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. The forecast variance can be reduced monotonically by including more components. For a given number of components, the flap method achieves maximum forecast variance reduction among linear projections.
Authors: Yangzhuoran Fin Yang [aut, cre]
Maintainer: Yangzhuoran Fin Yang <[email protected]>
License: GPL (>= 3)
Version: 0.2.0.9000
Built: 2024-11-17 05:10:41 UTC
Source: https://github.com/finyang/flap

Help Index


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

fc_comp

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

Phi

A pp by mm weight matrix mapping the original series into the components such that ct=Φztc_t = \Phi z_t where ctc_t is the vector of components and ztz_t is the vector of original series.

res

A TT by mm (in-sample) forecast residual matrix of the original series.

res_comp

A TT by pp (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 hh by mm 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)