This function computes the optimal multi-task linear forecast combination, as described in Girolimetto and Di Fonzo (2024)
Arguments
- base
A list of \(p\) numeric (\(h \times n\)) matrix or multivariate time series (
mts
class) containing the base forecasts to be reconciled; \(h\) is the forecast horizon, \(n\) is the total number of time series (\(n = n_u + n_b\)) and \(p\) is the total number of experts.- agg_mat
A (\(n_u \times n_b\)) numeric matrix representing the cross-sectional aggregation matrix, mapping the \(n_b\) bottom-level (free) variables into the \(n_u\) upper (constrained) variables.
- comb
A string specifying the reconciliation method. For details, see cscov.
- res
A list of \(p\) numeric (\(N \times n\)) matrix containing the in-sample residuals. This input is used to compute some covariance matrices.
- ...
Arguments passed on to cscov.
References
Girolimetto, D. and Di Fonzo, T. (2024), Coherent forecast combination for linearly constrained multiple time series, mimeo.
Examples
set.seed(123)
# (2 x 3) base forecasts matrix (simulated), expert 1
base1 <- matrix(rnorm(6, mean = c(20, 10, 10)), 2, byrow = TRUE)
# (10 x 3) in-sample residuals matrix (simulated), expert 1
res1 <- t(matrix(rnorm(n = 30), nrow = 3))
# (2 x 3) base forecasts matrix (simulated), expert 2
base2 <- matrix(rnorm(6, mean = c(20, 10, 10)), 2, byrow = TRUE)
# (10 x 3) in-sample residuals matrix (simulated), expert 2
res2 <- t(matrix(rnorm(n = 30), nrow = 3))
## BALANCED PANEL OF FORECASTS
# Base forecasts' and residuals' lists
brc <- list(base1, base2)
erc <- list(res1, res2)
# Aggregation matrix for Z = X + Y
A <- t(c(1,1))
rrc <- csocc(base = brc, agg_mat = A, comb = "shr", res = erc)
yc <- csmtc(base = brc, agg_mat = A, comb = "shr", res = erc)
M <- occmat(base = brc, agg_mat = A, comb = "shr", p = 2, res = erc)$M
M%*%t(yc)-t(rrc)
#> 3 x 2 Matrix of class "dgeMatrix"
#> h-1 h-2
#> [1,] 0.000000e+00 0.000000e+00
#> [2,] 1.776357e-15 0.000000e+00
#> [3,] 0.000000e+00 -1.776357e-15
## UNBALANCED PANEL OF FORECASTS
base2[, 2] <- res2[, 2] <- NA
# Base forecasts' and residuals' lists
bgc <- list(base1, base2)
egc <- list(res1, res2)
matNA <- matrix(1, 3, 2)
matNA[2,2] <- 0
# Aggregation matrix for Z = X + Y
A <- t(c(1,1))
rgc <- csocc(base = bgc, agg_mat = A, comb = "shr", res = egc)
yc <- csmtc(base = bgc, agg_mat = A, comb = "shr", res = egc)
M <- occmat(base = bgc, agg_mat = A, comb = "shr", p = 2, res = egc, matNA = matNA)$M
M%*%t(yc)-t(rgc)
#> 3 x 2 Matrix of class "dgeMatrix"
#> h-1 h-2
#> [1,] 0.000000e+00 0.000000e+00
#> [2,] 1.776357e-15 -1.776357e-15
#> [3,] 0.000000e+00 0.000000e+00