R/tdrec.R
tdrec.Rd
Top-down forecast reconciliation for genuine hierarchical/grouped time series, where the forecast of a `Total' (top-level series, expected to be positive) is disaggregated according to a proportional scheme given by a vector of proportions (weights). Besides the fulfillment of any aggregation constraint, the top-down reconciled forecasts should respect two main properties:
the top-level value remains unchanged;
all the bottom time series reconciled forecasts are non-negative.
The top-down procedure is extended to deal with both temporal and cross-temporal cases. Since this is a post-forecasting function, the vector of weights must be given in input by the user, and is not calculated automatically (see Examples).
tdrec(topf, C, m, weights)
(h×1) vector of the top-level base forecast to be disaggregated; h is the forecast horizon (for the lowest temporal aggregation order in temporal and cross-temporal cases).
(na×nb) cross-sectional (contemporaneous) matrix mapping the nb bottom level series into the na higher level ones.
Highest available sampling frequency per seasonal cycle (max. order of temporal aggregation, m), or a subset of the p factors of m.
vector of weights to be used to disaggregate topf: (nb×h) matrix in the cross-sectional framework; (m×h) matrix in the temporal framework; (nbm×h) matrix in the cross-temporal framework.
The function returns an (h×n) matrix of cross-sectionally reconciled forecasts, or an (h(k∗+m)×1) vector of top-down temporally reconciled forecasts, or an (n×h(k∗+m)) matrix of top-down cross-temporally reconciled forecasts.
Fix h=1, then ˜y=Swˆa1 where ˜y is the vector of reconciled forecasts, S is the summing matrix (whose pattern depends on which type of reconciliation is being performed), w is the vector of weights, and ˆa1 is the top-level value to be disaggregated.
Athanasopoulos, G., Ahmed, R.A., Hyndman, R.J. (2009), Hierarchical forecasts for Australian domestic tourism, International Journal of Forecasting, 25, 1, 146–166.
data(FoReco_data)
### CROSS-SECTIONAL TOP-DOWN RECONCILIATION
# Cross sectional aggregation matrix
C <- FoReco_data$C
# monthly base forecasts
mbase <- FoReco2matrix(FoReco_data$base, m = 12)$k1
obs_1 <- FoReco_data$obs$k1
# average historical proportions
props <- colMeans(obs_1[1:168,-c(1:3)]/obs_1[1:168,1])
cs_td <- tdrec(topf = mbase[,1], C = C, weights = props)
### TEMPORAL TOP-DOWN RECONCILIATION
# top ts base forecasts ([lowest_freq' ... highest_freq']')
top_obs12 <- FoReco_data$obs$k12[1:14,1]
bts_obs1 <- FoReco_data$obs$k1[1:168,1]
# average historical proportions
props <- colMeans(matrix(bts_obs1, ncol = 12, byrow = TRUE)/top_obs12)
topbase <- FoReco_data$base[1, 1]
t_td <- tdrec(topf = topbase, m = 12, weights = props)
### CROSS-TEMPORAL TOP-DOWN RECONCILIATION
top_obs <- FoReco_data$obs$k12[1:14,1]
bts_obs <- FoReco_data$obs$k1[1:168,-c(1:3)]
bts_obs <- lapply(1:5, function(x) matrix(bts_obs[,x], nrow=14, byrow = TRUE))
bts_obs <- do.call(cbind, bts_obs)
# average historical proportions
props <- colMeans(bts_obs/top_obs)
ct_td <- tdrec(topf = topbase, m = 12, C = C, weights = props)