A two-level hierarchy with \(n = 8\) monthly time series. In the cross-sectional framework, at any time it is \(Tot = A + B + C\), \(A = AA + AB\) and \(B = BA + BB\) (the bottom time series being \(AA\), \(AB\), \(BA\), \(BB\), and \(C\), it is \(n_b = 5\)). The monthly observations are aggregated to their annual (\(k = 12\)), semi-annual (\(k = 6\)), four-monthly (\(k = 4\)), quarterly (\(k = 3\)), and bi-monthly (\(k = 2\)) counterparts. The monthly bottom time series are simulated from five different SARIMA models (see Using the `FoReco` package). There are 180 (15 years) monthly observations: the first 168 values (14 years) are used as training set, and the last 12 form the test set.

data(FoReco_data)

Format

An object of class "list":

base

(\(8 \times 28\)) matrix of base forecasts. Each row identifies a time series and the forecasts are ordered as [lowest_freq' ... highest_freq']'.

test

(\(8 \times 28\)) matrix of test set. Each row identifies a time series and the observed values are ordered as [lowest_freq' ... highest_freq']'.

res

(\(8 \times 392\)) matrix of in-sample residuals. Each row identifies a time series and the in-sample residuals are ordered as [lowest_freq' ... highest_freq']'.

C

(\(3 \times 5\)) cross-sectional (contemporaneous) aggregation matrix.

obs

List of the observations at any levels and temporal frequencies.

Examples

# \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")
# }