This function provides an approximation of the cross-temporal base forecasts errors covariance matrix using different reconciliation methods (Di Fonzo and Girolimetto, 2023, Girolimetto et al., 2023).
Usage
ctcov(comb = "ols", n = NULL, agg_mat = NULL, agg_order = NULL, res = NULL,
tew = "sum", mse = TRUE, shrink_fun = shrink_estim, ...)
Arguments
- comb
A string specifying the reconciliation method.
Ordinary least squares:
"
ols
" (default) - identity error covariance.
Weighted least squares:
"
str
" - structural variances."
csstr
" - cross-sectional structural variances."
testr
" - temporal structural variances."
wlsh
" - hierarchy variances (usesres
)."
wlsv
" - series variances (usesres
).
Generalized least squares (uses
res
):"
acov
" - series auto-covariance."
bdshr
"/"bdsam
" - shrunk/sample block diagonal cross-sectional covariance."
Sshr
"/"Ssam
" - series shrunk/sample covariance."
shr
"/"sam
" - shrunk/sample covariance."
hbshr
"/"hbsam
" - shrunk/sample high frequency bottom time series covariance."
bshr
"/"bsam
" - shrunk/sample bottom time series covariance."
hshr
"/"hsam
" - shrunk/sample high frequency covariance.
- n
Cross-sectional number of variables.
- 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.
- agg_order
Highest available sampling frequency per seasonal cycle (max. order of temporal aggregation, \(m\)), or a vector representing a subset of \(p\) factors of \(m\).
- res
A (\(n \times N(k^\ast+m)\)) optional numeric matrix containing the in-sample residuals at all the temporal frequencies ordered from the lowest frequency to the highest frequency (columns) for each variable (rows). This matrix is used to compute some covariance matrices.
- tew
A string specifying the type of temporal aggregation. Options include: "
sum
" (simple summation, default), "avg
" (average), "first
" (first value of the period), and "last
" (last value of the period).- 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.
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
Girolimetto, D., Athanasopoulos, G., Di Fonzo, T. and Hyndman, R.J. (2024), Cross-temporal probabilistic forecast reconciliation: Methodological and practical issues. International Journal of Forecasting, 40, 3, 1134-1151. doi:10.1016/j.ijforecast.2023.10.003
Examples
set.seed(123)
# Aggregation matrix for Z = X + Y
A <- t(c(1,1))
# (3 x 70) in-sample residuals matrix (simulated),
# agg_order = 4 (annual-quarterly)
res <- rbind(rnorm(70), rnorm(70), rnorm(70))
cov1 <- ctcov("ols", n = 3, agg_order = 4) # OLS methods
cov2 <- ctcov("str", agg_mat = A, agg_order = 4) # STR methods
cov3 <- ctcov("csstr", agg_mat = A, agg_order = 4) # CSSTR methods
cov4 <- ctcov("testr", n = 3, agg_order = 4) # TESTR methods
cov5 <- ctcov("wlsv", agg_order = 4, res = res) # WLSv methods
cov6 <- ctcov("wlsh", agg_order = 4, res = res) # WLSh methods
cov7 <- ctcov("shr", agg_order = 4, res = res) # SHR methods
cov8 <- ctcov("sam", agg_order = 4, res = res) # SAM methods
cov9 <- ctcov("acov", agg_order = 4, res = res) # ACOV methods
cov10 <- ctcov("Sshr", agg_order = 4, res = res) # Sshr methods
cov11 <- ctcov("Ssam", agg_order = 4, res = res) # Ssam methods
cov12 <- ctcov("hshr", agg_order = 4, res = res) # Hshr methods
cov13 <- ctcov("hsam", agg_order = 4, res = res) # Hsam methods
cov14 <- ctcov("hbshr", agg_mat = A, agg_order = 4, res = res) # HBshr methods
#> [1] 0.5736559
cov15 <- ctcov("hbsam", agg_mat = A, agg_order = 4, res = res) # HBsam methods
cov16 <- ctcov("bshr", agg_mat = A, agg_order = 4, res = res) # Bshr methods
cov17 <- ctcov("bsam", agg_mat = A, agg_order = 4, res = res) # Bsam methods
cov18 <- ctcov("bdshr", agg_order = 4, res = res) # BDshr methods
cov19 <- ctcov("bdsam", agg_order = 4, res = res) # BDsam methods
# Custom covariance matrix
ctcov.ols2 <- function(comb, x) diag(x)
cov20 <- ctcov(comb = "ols2", x = 21) # == ctcov("ols", n = 3, agg_order = 4)