FoReco (version 0.1.1)

FoReco_data: Forecast reconciliation for a simulated hierarchical time series

Description

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 (nb = 5 at the bottom level). For monthly data, the observations are aggregated to annual (k = 12), semi-annual (k = 6), four-monthly (k = 4), quarterly (k = 3), and bi-monthly (k = 2) observations. 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.

Usage

data(FoReco_data)

Arguments

Format

An object of class "list":

base

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

test

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

res

(8 x 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 x 5) cross-sectional (contemporaneous) aggregation matrix.

obs

List of the observations at any levels and temporal frequencies.

Examples

Run this code
# NOT RUN {
data(FoReco_data)
# Cross-sectional reconciliation for all temporal aggregation levels
# (monthly, bi-monthly, ..., annual)
K <- c(1,2,3,4,6,12)
hts_recf <- NULL
for(i in 1:length(K)){
  # base forecasts
  id <- which(simplify2array(strsplit(colnames(FoReco_data$base),
                                      split = "_"))[1, ] == paste("k", K[i], sep=""))
  mbase <- t(FoReco_data$base[, id])
  # residuals
  id <- which(simplify2array(strsplit(colnames(FoReco_data$res),
                                      split = "_"))[1, ] == "k1")
  mres <- t(FoReco_data$res[, id])
  hts_recf[[i]] <- htsrec(mbase, C = FoReco_data$C, comb = "shr",
                          res = mres, keep = "recf")
}
names(hts_recf) <- paste("k", K, sep="")

# Forecast reconciliation through temporal hierarchies for all time series
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
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
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
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
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