FoReco (version 0.1.1)

iterec: Iterative heuristic cross-temporal forecast reconciliation

Description

Iterative procedure which produces cross-temporally reconciled forecasts by alternating forecast reconciliation along one single dimension (either cross-sectional or temporal) at each iteration step. Each iteration consists in the first two steps of the heuristic KA procedure, so the forecasts are reconciled by alternating cross-sectional (contemporaneous) reconciliation, and reconciliation through temporal hierarchies in a cyclic fashion. The choice of the dimension along with the first reconciliation step in each iteration is performed is up to the user (param start_rec), and there is no particular reason why one should perform the temporal reconciliation first, and the cross-sectional reconciliation then. The iterative procedure allows the user to get non-negative reconciled forecasts.

Usage

iterec(basef, m, C, thf_comb, hts_comb, Ut, nb, res, W,
       Omega, mse = TRUE, corpcor = FALSE,type = "M",
       sol = "direct", nn = FALSE, maxit = 100, tol = 1e-5,
       start_rec = "thf", note = TRUE, plot = "mti",
       settings = osqpSettings(verbose = FALSE, eps_abs = 1e-5,
       eps_rel = 1e-5, polish_refine_iter = 100, polish = TRUE))

Arguments

basef

(n x h(k* + m)) matrix of base forecasts to be reconciled; n is the total number of variables, m is the highest frequency, k* is the sum of (p-1) factors of m, excluding m, and h is the forecast horizon. Each row identifies, a time series, and the forecasts are ordered as [lowest_freq' ... highest_freq']'.

m

Highest available sampling frequency per seasonal cycle (max. order of temporal aggregation).

C

(na x nb) cross-sectional (contemporaneous) matrix mapping the bottom level series into the higher level ones.

thf_comb

Type of the ((k* + m) x (k* + m)) covariance matrix to be used in the temporal reconciliation, see more in comb param of thfrec.

hts_comb

Type of the (n x n) covariance matrix to be used in the cross-sectional reconciliation, see more in comb param of htsrec.

Ut

Zero constraints cross-sectional (contemporaneous) kernel matrix \((\textbf{U}'\textbf{Y} = \mathbf{0})\) spanning the null space valid for the reconciled forecasts. It can be used instead of parameter C, but in this case nb (n = na + nb) is needed. If the hierarchy admits a structural representation, Ut has dimension (na x n).

nb

Number of bottom time series; if C is present, nb is not used.

res

(n x N(k* + m)) matrix containing the residuals at all the temporal frequencies ordered [lowest_freq' ... highest_freq']' (columns) for each variable (row), needed to estimate the covariance matrix when hts_comb = {"wls", "shr", "sam"} and/or hts_comb = {"wlsv", "wlsh", "acov", "strar1", "sar1", "har1", "shr", "sam"}. The row must be in the same order as basef.

W

This option permits to directly enter the covariance matrix in the cross-sectional reconciliation, see more in W param of htsrec.

Omega

This option permits to directly enter the covariance matrix in the reconciliation through temporal hierarchies, see more in Omega param of thfrec.

mse

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.

corpcor

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.

type

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.

sol

Solution technique for the reconciliation problem: either "direct" for the direct solution or "osqp" for the numerical solution (solving a linearly constrained quadratic program using solve_osqp).

nn

Logical value: TRUE if non-negative reconciled forecasts are wished.

maxit

Max number of iteration (100, default).

tol

Convergence tolerance (1e-5, default).

start_rec

Dimension along with the first reconciliation step in each iteration is performed: it start from temporal reconciliation with "thf" (default), from cross-sectional with "hts" and it does both reconciliation with "auto".

note

If note = TRUE (default) the function writes some notes to the console, otherwise no note is produced (also no plot).

plot

Some useful plots: "mti" (default) marginal trend inconsistencies, "pat" step by step inconsistency pattern for each iteration, "distf" distance forecasts iteration i and i-1, "all" all the plots.

settings

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).

Value

iterec returns a list with:

recf

(n x h(k* + m)) matrix of reconciled forecasts.

d_cs

Cross-sectional incoherence at each iteration.

d_te

Temporal incoherence at each iteration.

start_rec

Starting coherence dimension (thf or hts).

tol

Tolerance.

flag

Control code (see details).

time

Elapsed time.

dist

If start_rec = "auto", matrix of distances of the forecasts reconciled from the base.

Details

The above procedure can be seen as an extension of the well known iterative proportional fitting procedure (Deming and Stephan, 1940, Johnston and Pattie, 1993), also known as RAS method (Miller and Blair, 2009), to adjust the internal cell values of a two-dimensional matrix until they sum to some predetermined row and column totals. In that case the adjustment follows a proportional adjustment scheme, whereas in the cross-temporal reconciliation framework each adjustment step is made according to the penalty function associated to the single-dimension reconciliation procedure adopted.

Control status of iterative reconciliation:

-2

Temporal/Cross-sectional reconciliation does not work.

-1

Convergence not achieved (maximum iteration limit reached).

0

Convergence achieved.

+1

Convergence achieved: incoherence has increased in the next iteration (at least one time).

+2

Convergence achieved: incoherence has increased in the next two or more iteration (at least one time).

+3

The forecasts are already reconciled.

References

Deming, E., Stephan, F.F. (1940), On a least squares adjustment of a sampled frequency table when the expected marginal totals are known, The Annals of Mathematical Statistics, 11, 4, 427<U+2013>444.

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.

Johnston, R.J., Pattie, C.J. (1993), Entropy-Maximizing and the Iterative Proportional Fitting Procedure, The Professional Geographer, 45, 3, 317<U+2013>322.

Kourentzes, N., Athanasopoulos, G. (2019), Cross-temporal coherent forecasts for Australian tourism, Annals of Tourism Research, 75, 393-409.

Miller, R.E., Blair, P.D. (2009), Input-output analysis: foundations and extensions, 2nd edition, New York, Cambridge University Press.

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.

Examples

Run this code
# NOT RUN {
data(FoReco_data)
obj <- 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")
# }
# NOT RUN {
# }

Run the code above in your browser using DataCamp Workspace