Forecast reconciliation of one time series through temporal hierarchies (Athanasopoulos et al., 2017). The reconciled forecasts are calculated either through a projection approach (Byron, 1978), or the equivalent structural approach by Hyndman et al. (2011). Moreover, the classic bottom-up approach is available.
thfrec(basef, m, comb, res, mse = TRUE, corpcor = FALSE, Omega,
type = "M", sol = "direct", nn = FALSE, keep = "list",
settings = osqpSettings(verbose = FALSE, eps_abs = 1e-5,
eps_rel = 1e-5, polish_refine_iter = 100, polish=TRUE))
Vector of base forecasts to be reconciled, containing the forecasts at all the needed temporal frequencies ordered as [lowest_freq' ... highest_freq']'.
Highest available sampling frequency per seasonal cycle (max. order of temporal aggregation).
Type of the reconciliation. Except for bottom up, all other options
correspond to a different ((k* + m) x (k* + m)
) covariance matrix,
k*
is the sum of (p-1
) factors of m
(excluding m
):
bu (Bottom-up);
ols (Identity);
struc (Structural variances);
wlsv (Series variances);
wlsh (Hierarchy variances);
acov (Auto-covariance matrix);
strar1 (Structural Markov);
sar1 (Series Markov);
har1 (Hierarchy Markov);
shr (Shrunk cross-covariance matrix);
sam (Sample cross-covariance matrix);
omega use your personal matrix Omega in param Omega
.
vector containing the in-sample residuals at all the temporal frequencies
ordered as basef
, i.e. [lowest_freq' ... highest_freq']', needed to
estimate the covariance matrix when comb =
{"wlsv",
"wlsh",
"acov",
"strar1",
"sar1",
"har1",
"shr",
"sam"}
.
Logical value: TRUE
(default) calculates the
covariance matrix of the in-sample residuals (when necessary) according to the original
hts and thief formulation: no mean correction, T as denominator.
Logical value: TRUE
if corpcor (Sch<U+00E4>fer et
al., 2017) must be used to shrink the sample covariance matrix according to
Sch<U+00E4>fer and Strimmer (2005), otherwise the function uses the same
implementation as package hts.
This option permits to directly enter the covariance matrix:
Omega
must be a p.d. ((k* + m) x (k* + m)
) matrix;
if comb
is different from "omega
", Omega
is not used.
Approach used to compute the reconciled forecasts: "M"
for
the projection approach with matrix M (default), or "S"
for the
structural approach with summing matrix S.
Solution technique for the reconciliation problem: either "direct"
(default) for the direct
solution or "osqp"
for the numerical solution (solving a linearly constrained quadratic
program using solve_osqp
).
Logical value: TRUE
if non-negative reconciled forecasts are wished.
Return a list object of the reconciled forecasts at all levels.
Settings for osqp (object osqpSettings
). The default options
are: verbose = FALSE
, eps_abs = 1e-5
, eps_rel = 1e-5
,
polish_refine_iter = 100
and polish = TRUE
. For details, see the
osqp documentation (Stellato et al., 2019).
If the parameter keep
is equal to "recf"
, then the function
returns only the reconciled forecasts vector, otherwise (keep="all"
)
it returns a list that mainly depends on what type of representation (type
)
and methodology (sol
) have been used:
recf
(h(k* + m) x 1
) reconciled forecasts vector.
Omega
Covariance matrix used for forecast reconciliation.
nn_check
Number of negative values (if zero, there are no values below zero).
rec_check
Logical value: has the hierarchy been respected?
M
(type="M"
and type="direct"
)Projection matrix (projection approach)
G
(type="S"
and type="direct"
)Projection matrix (structural approach).
S
(type="S"
and type="direct"
)Temporal summing matrix, R.
info
(type="osqp"
)matrix with some useful indicators (columns)
for each forecast horizon h
(rows): run time (run_time
) number of iteration,
norm of primal residual (pri_res
), status of osqp's solution (status
) and
polish's status (status_polish
).
Only if comb = "bu", the function returns recf, S and M.
In case of non-negativity constraints, there are two ways:
sol = "direct"
and nn = TRUE
: the base forecasts
will be reconciled at first without non-negativity constraints, then, if negative reconciled
values are present, the "osqp"
solver is used.
sol = "osqp"
and nn = TRUE
: the base forecasts will be
reconciled through the "osqp"
solver.
Athanasopoulos, G., Hyndman, R.J., Kourentzes, N., Petropoulos, F. (2017), Forecasting with Temporal Hierarchies, European Journal of Operational Research, 262, 1, 60-74.
Byron, R.P. (1978), The estimation of large social accounts matrices, Journal of the Royal Statistical Society A, 141, 3, 359-367.
Di Fonzo, T., Girolimetto, D. (2020), Cross-Temporal Forecast Reconciliation: Optimal Combination Method and Heuristic Alternatives, Department of Statistical Sciences, University of Padua, arXiv:2006.08570.
Hyndman, R.J., Ahmed, R.A., Athanasopoulos, G., Shang, H.L. (2011), Optimal combination forecasts for hierarchical time series, Computational Statistics & Data Analysis, 55, 9, 2579-2589.
Nystrup, P., Lindstr<U+00F6>m, E., Pinson, P., Madsen, H. (2020), Temporal hierarchies with autocorrelation for load forecasting, European Journal of Operational Research, 280, 1, 876-888.
Sch<U+00E4>fer, J.L., Opgen-Rhein, R., Zuber, V., Ahdesmaki, M., Duarte Silva, A.P., Strimmer, K. (2017), Package `corpcor', R package version 1.6.9 (April 1, 2017), https://CRAN.R-project.org/package= corpcor.
Sch<U+00E4>fer, J.L., Strimmer, K. (2005), A Shrinkage Approach to Large-Scale Covariance Matrix Estimation and Implications for Functional Genomics, Statistical Applications in Genetics and Molecular Biology, 4, 1.
Stellato, B., Banjac, G., Goulart, P., Bemporad, A., Boyd, S. (2018). OSQP: An Operator Splitting Solver for Quadratic Programs, arXiv:1711.08013.
Stellato, B., Banjac, G., Goulart, P., Boyd, S., Anderson, E. (2019), OSQP: Quadratic Programming Solver using the 'OSQP' Library, R package version 0.6.0.3 (October 10, 2019), https://CRAN.R-project.org/package=osqp.
# NOT RUN {
data(FoReco_data)
# top ts base forecasts ([lowest_freq' ... highest_freq']')
topbase <- FoReco_data$base[1, ]
# top ts residuals ([lowest_freq' ... highest_freq']')
topres <- FoReco_data$res[1, ]
obj <- thfrec(topbase, m = 12, comb = "acov", res = topres)
# }
Run the code above in your browser using DataLab