# \donttest{
data(FoReco_data)
# Cross-sectional reconciliation for all temporal aggregation levels
# (annual, ..., bi-monthly, monthly)
K <- c(12, 6, 4, 3, 2, 1)
mbase <- FoReco2matrix(FoReco_data$base, m = 12)
mres <- FoReco2matrix(FoReco_data$res, m = 12)
hts_recf <- lapply(K, function(k){
htsrec(mbase[[paste0("k", k)]], C = FoReco_data$C, comb = "shr",
res = mres[[paste0("k", k)]], keep = "recf")
})
names(hts_recf) <- paste("k", K, sep="")
# Forecast reconciliation through temporal hierarchies for all time series
# comb = "acov"
n <- NROW(FoReco_data$base)
thf_recf <- matrix(NA, n, NCOL(FoReco_data$base))
dimnames(thf_recf) <- dimnames(FoReco_data$base)
for(i in 1:n){
# ts base forecasts ([lowest_freq' ... highest_freq']')
tsbase <- FoReco_data$base[i, ]
# ts residuals ([lowest_freq' ... highest_freq']')
tsres <- FoReco_data$res[i, ]
thf_recf[i,] <- thfrec(tsbase, m = 12, comb = "acov",
res = tsres, keep = "recf")
}
# Iterative cross-temporal reconciliation
# Each iteration: t-acov + cs-shr
ite_recf <- iterec(FoReco_data$base, note=FALSE,
m = 12, C = FoReco_data$C,
thf_comb = "acov", hts_comb = "shr",
res = FoReco_data$res, start_rec = "thf")$recf
# Heuristic first-cross-sectional-then-temporal cross-temporal reconciliation
# cs-shr + t-acov
cst_recf <- cstrec(FoReco_data$base, m = 12, C = FoReco_data$C,
thf_comb = "acov", hts_comb = "shr",
res = FoReco_data$res)$recf
# Heuristic first-temporal-then-cross-sectional cross-temporal reconciliation
# t-acov + cs-shr
tcs_recf <- tcsrec(FoReco_data$base, m = 12, C = FoReco_data$C,
thf_comb = "acov", hts_comb = "shr",
res = FoReco_data$res)$recf
# Optimal cross-temporal reconciliation
# comb = "bdshr"
oct_recf <- octrec(FoReco_data$base, m = 12, C = FoReco_data$C,
comb = "bdshr", res = FoReco_data$res, keep = "recf")
# }
Run the code above in your browser using DataLab