set.seed(123)
A <- t(c(1,1)) # Aggregation matrix for Z = X + Y
m <- 4 # from quarterly to annual temporal aggregation
# (100 x 14) base forecasts sample matrix (simulated), m = 4, h = 2, n = 3
sample <- simplify2array(lapply(1:100, function(x){
rbind(rnorm(14, rep(c(20, 10, 5), 2*c(1, 2, 4))),
rnorm(14, rep(c(10, 5, 2.5), 2*c(1, 2, 4))),
rnorm(14, rep(c(10, 5, 2.5), 2*c(1, 2, 4))))
}))
# (3 x 70) in-sample residuals matrix (simulated)
res <- rbind(rnorm(70), rnorm(70), rnorm(70))
# Top-down probabilistic reconciliation
reco_dist_td <- ctsmp(sample[1, 1:2, , drop = FALSE], agg_order = m,
agg_mat = A, fun = cttd, weights = matrix(runif(8), 2))
# Middle-out probabilistic reconciliation
reco_dist_mo <- ctsmp(sample[1, 3:6, , drop = FALSE], agg_order = m,
agg_mat = A, fun = ctmo, weights = matrix(runif(8), 2),
id_rows = 1, order = 2)
# Bottom-up probabilistic reconciliation
reco_dist_bu <- ctsmp(sample[-1,-c(1:6), ], agg_order = m, agg_mat = A,
fun = ctbu)
# Level conditional coherent probabilistic reconciliation
reco_dist_lcc <- ctsmp(sample, agg_order = m, agg_mat = A, fun = ctlcc)
# Optimal cross-sectional probabilistic reconciliation
reco_dist_opt <- ctsmp(sample, agg_order = m, agg_mat = A, res = res,
comb = "bdshr")
Run the code above in your browser using DataLab