Skip to contents

This function provides an approximation of the cross-sectional base forecasts errors covariance matrix using different reconciliation methods (see Wickramasuriya et al., 2019 and Di Fonzo and Girolimetto, 2023).

Usage

cscov(comb = "ols", n = NULL, agg_mat = NULL, res, mse = TRUE,
      shrink_fun = shrink_estim, ...)

Arguments

comb

A string specifying the reconciliation method.

  • Ordinary least squares:

    • "ols" (default) - identity error covariance matrix.

  • Weighted least squares:

    • "str" - structural variances.

    • "wls" - series variances (uses res).

  • Generalized least squares:

    • "shr"/"sam" - shrunk/sample covariance (uses res).

n

Number of variables (\(n = n_a + n_b\)).

agg_mat

A (\(n_a \times n_b\)) numeric matrix representing the cross-sectional aggregation matrix. It maps the \(n_b\) bottom-level (free) variables into the \(n_a\) upper (constrained) variables.

res

An (\(N \times n\)) optional numeric matrix containing the in-sample residuals. This matrix is used to compute some covariance matrices.

mse

If TRUE (default) the residuals used to compute the covariance matrix are not mean-corrected.

shrink_fun

Shrinkage function of the covariance matrix, shrink_estim (default).

...

Not used.

Value

A (\(n \times n\)) symmetric positive (semi-)definite matrix.

References

Di Fonzo, T. and Girolimetto, D. (2023), Cross-temporal forecast reconciliation: Optimal combination method and heuristic alternatives, International Journal of Forecasting, 39, 1, 39-57. doi:10.1016/j.ijforecast.2021.08.004

Wickramasuriya, S.L., Athanasopoulos, G. and Hyndman, R.J. (2019), Optimal forecast reconciliation for hierarchical and grouped time series through trace minimization, Journal of the American Statistical Association, 114, 526, 804-819. doi:10.1080/01621459.2018.1448825

See also

Cross-sectional framework: csboot(), csbu(), cslcc(), csmo(), csrec(), cstd(), cstools()

Examples

# Aggregation matrix for Z = X + Y
A <- t(c(1,1))
# (10 x 3) in-sample residuals matrix (simulated)
res <- t(matrix(rnorm(n = 30), nrow = 3))

cov1 <- cscov("ols", n = 3)          # OLS methods
cov2 <- cscov("str", agg_mat = A)   # STR methods
cov3 <- cscov("wls", res = res)      # WLS methods
cov4 <- cscov("shr", res = res)      # SHR methods
cov5 <- cscov("sam", res = res)      # SAM methods

# Custom covariance matrix
cscov.ols2 <- function(comb, x) diag(x)
cscov(comb = "ols2", x = 3) # == cscov("ols", n = 3)
#>      [,1] [,2] [,3]
#> [1,]    1    0    0
#> [2,]    0    1    0
#> [3,]    0    0    1