octrec {FoReco} | R Documentation |
Optimal combination cross-temporal forecast reconciliation
Description
Optimal (in least squares sense) combination cross-temporal forecast reconciliation. The reconciled forecasts are calculated either through a projection approach (Byron, 1978), or the equivalent structural approach by Hyndman et al. (2011).
Usage
octrec(basef, m, C, comb, res, Ut, nb, mse = TRUE, corpcor = FALSE,
type = "M", sol = "direct", keep = "list", v = NULL, nn = FALSE,
nn_type = "osqp", settings = list(), bounds = NULL, W = NULL,
Omega = NULL)
Arguments
basef |
(\(n \times h(k^\ast+m)\)) matrix of base forecasts to be reconciled, \(\widehat{\mathbf{Y}}\); \(n\) is the total number of variables, \(m\) is the highest time frequency, \(k^\ast\) is the sum of (a subset of) (\(p-1\)) factors of \(m\), excluding \(m\), and \(h\) is the forecast horizon for the lowest frequency time series. 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, \(m\)), or a subset of \(p\) factors of \(m\). |
C |
(\(n_a \times n_b\)) cross-sectional (contemporaneous) matrix mapping the bottom level series into the higher level ones. |
comb |
Type of the reconciliation. It corresponds to a specific (\(n(k\ast + m) \times n(k^\ast + m)\)) covariance matrix (Di Fonzo and Girolimetto 2023, Girolimetto et al. 2023), where \(k^\ast\) is the sum of (a subset of) (\(p-1\)) factors of \(m\) (\(m\) is not considered) and \(n\) is the number of variables:
|
res |
(\(n \times N(k^\ast + 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. |
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
|
nb |
Number of bottom time series; if |
mse |
Logical value: |
corpcor |
Logical value: |
type |
Approach used to compute the reconciled forecasts: |
sol |
Solution technique for the reconciliation problem: either
|
keep |
Return a list object of the reconciled forecasts at all levels (if keep = "list") or only the reconciled forecasts matrix (if keep = "recf"). |
v |
vector index of the fixed base forecast (\(\mbox{min}(v) > 0\) and \(\mbox{max}(v) < n(k^\ast + m)\)). |
nn |
Logical value: |
nn_type |
"osqp" (default), "KAnn" (only |
settings |
Settings for osqp (object |
bounds |
(\(n(k^\ast + m) \times 2\)) matrix of the bounds on the variables: the first column is the lower bound, and the second column is the upper bound. |
W , Omega |
This option permits to directly enter the covariance matrix:
|
Details
Considering contemporaneous and temporal dimensions in the same framework requires to extend and adapt the notations used in htsrec and thfrec. To do that, we define the matrix containing the base forecasts at any considered temporal frequency as \[ \widehat{\textbf{Y}}_{n \times h(k^\ast+m))} = \left[\begin{array}{ccccc} \widehat{\textbf{A}}^{[m]} & \widehat{\textbf{A}}^{[k_{p-1}]} & \cdots & \widehat{\textbf{A}}^{[k_2]} & \widehat{\textbf{A}}^{[1]} \cr \widehat{\textbf{B}}^{[m]} & \widehat{\textbf{B}}^{[k_{p-1}]} & \cdots & \widehat{\textbf{B}}^{[k_2]} & \widehat{\textbf{B}}^{[1]} \end{array} \right] \qquad k \in {\cal K},\] where \(\cal K\) is a subset of \(p\) factors of \(m\) and, \(\widehat{\textbf{B}}^{[k]}\) and \(\widehat{\textbf{A}}^{[k]}\) are the matrices containing the \(k\)-order temporal aggregates of the bts and uts, of dimension (\(n_b \times h m/k\)) and (\(n_a \times h m/k\)), respectively.
Let us consider the multivariate regression model
\[\widehat{\mathbf{Y}} = \mathbf{Y} + \mathbf{E} ,\]
where the involved matrices have each dimension
\([n \times (k^\ast+m)]\) and contain, respectively, the base
(\(\widehat{\mathbf{Y}}\)) and the target forecasts
(\(\mathbf{Y}\)), and the coherency errors (\(\mathbf{E}\)) for
the \(n\) component variables of the linearly constrained time series
of interest. For each variable, \(k^\ast + m\) base forecasts are
available, pertaining to all aggregation levels of the temporal hierarchy
for a complete cycle of high-frequency observation, \(m\). Consider
now two vectorized versions of model, by transforming the matrices either
in original form:
\[\mbox{vec}\left(\widehat{\mathbf{Y}}\right) =
\mbox{vec}\left(\mathbf{Y}\right) + \mathbf{\varepsilon} \; \mbox{ with }
\; \mathbf{\varepsilon} = \mbox{vec}\left(\mathbf{E}\right)\]
or in transposed form:
\[\mbox{vec}\left(\widehat{\mathbf{Y}}'\right) =
\mbox{vec}\left(\mathbf{Y}'\right) + \mathbf{\eta} \; \mbox{ with }
\; \mathbf{\eta} = \mbox{vec}\left(\mathbf{E}'\right).\]
Denote with \(\mathbf{P}\) the \([n(k^\ast+m) \times n(k^\ast+m)]\)
commutation matrix such that
\(\mathbf{P}\mbox{vec}(\mathbf{Y}) = \mbox{vec}(\mathbf{Y}')\),
\(\mathbf{P}\mbox{vec}(\widehat{\mathbf{Y}}) = \mbox{vec}(\widehat{\mathbf{Y}}')\)
and \(\mathbf{P}\mathbf{\varepsilon} = {\bf \eta}\).
Let \(\mathbf{W} = \mathrm{E}[\mathbf{\varepsilon\varepsilon}']\) be the
covariance matrix of vector \(\mathbf{\varepsilon}\), and
\(\mathbf{\Omega} = \mathrm{E}[\mathbf{\eta\eta}']\) the covariance matrix of
vector \(\mathbf{\eta}\). Clearly, \(\mathbf{W}\) and
\(\mathbf{\Omega}\) are different parameterizations of the same
statistical object for which the following relationships hold:
\[\mathbf{\Omega} = \mathbf{P}\mathbf{W}\mathbf{P}',
\qquad \mathbf{W} = \mathbf{P}' \mathbf{\Omega}\mathbf{P} .\]
In order to apply the general point forecast reconciliation according to the
projection approach (type = "M"
) to a cross-temporal forecast
reconciliation problem, we may consider either two vec-forms , e.g.
if we follow the first:
\[
\tilde{\mathbf{y}}= \hat{\mathbf{y}} - \mathbf{\Omega}\mathbf{H}\left(
\mathbf{H}'\mathbf{\Omega}\mathbf{H}\right)^{-1}\mathbf{H}'\hat{\mathbf{y}} =
{\mathbf{M}}\hat{\mathbf{y}},\]
where \(\widehat{\mathbf{y}} = \mbox{vec}(\widehat{\mathbf{Y}}')\) is the
row vectorization of the base forecasts matrix \(\widehat{\mathbf{Y}}\)
The alternative equivalent solution (type = "S"
) (following the
structural reconciliation approach by Hyndman et al., 2011) is
\[\widetilde{\mathbf{y}} = \widetilde{\mathbf{S}}\left(\widetilde{\mathbf{S}}'
\mathbf{\Omega}^{-1}\widetilde{\mathbf{S}}\right)^{-1}\widetilde{\mathbf{S}}'
\mathbf{\Omega}^{-1}\widehat{\mathbf{y}} = \widetilde{\mathbf{S}}\mathbf{G}\widehat{\mathbf{y}}.\]
where \(\widetilde{\mathbf{S}}\) is the cross-temporal summing matrix.
Bounds on the reconciled forecasts
When the reconciliation uses the optimization package osqp,
the user may impose bounds on the reconciled forecasts.
The parameter bounds
permits to consider lower (\(\mathbf{a}\)) and
upper (\(\mathbf{b}\)) bounds like \(\mathbf{a} \leq
\widetilde{\mathbf{y}} \leq \mathbf{b}\), where \(\widehat{\mathbf{y}} =
\mbox{vec}(\widehat{\mathbf{Y}}')\), such that:
\[ \begin{array}{c}
a_1 \leq \widetilde{y}_1 \leq b_1 \cr
\dots \cr
a_{n(k^\ast + m)} \leq \widetilde{y}_{n(k^\ast + m)} \leq b_{n(k^\ast + m)} \cr
\end{array} \Rightarrow
\mbox{bounds} = [\mathbf{a} \; \mathbf{b}] =
\left[\begin{array}{cc}
a_1 & b_1 \cr
\vdots & \vdots \cr
a_{n(k^\ast + m)} & b_{n(k^\ast + m)} \cr
\end{array}\right],\]
where \(a_i \in [- \infty, + \infty]\) and \(b_i \in [- \infty, + \infty]\).
If \(y_i\) is unbounded, the i-th row of bounds
would be equal
to c(-Inf, +Inf)
.
Notice that if the bounds
parameter is used, sol = "osqp"
must be used.
This is not true in the case of non-negativity constraints:
-
sol = "direct"
: first the base forecasts are reconciled without non-negativity constraints, then, if negative reconciled values are present, the"osqp"
solver is used; -
sol = "osqp"
: the base forecasts are reconciled using the"osqp"
solver.
In this case it is not necessary to build a matrix containing
the bounds, and it is sufficient to set nn = "TRUE"
.
Non-negative reconciled forecasts may be obtained by setting nn_type
alternatively as:
-
nn_type = "sntz"
("set-negative-to-zero") -
nn_type = "osqp"
(Stellato et al., 2020)
Value
If the parameter keep
is equal to "recf"
, then the function
returns only the (\(n \times h(k^\ast + m)\)) reconciled forecasts
matrix, otherwise (keep="all"
) it returns a list that mainly depends
on what type of representation (type
) and solution technique
(sol
) have been used:
recf |
(\(n \times h(k^\ast + m)\)) reconciled forecasts matrix, \(\widetilde{\textbf{Y}}\). |
Omega |
Covariance matrix used for reconciled forecasts (\(\mbox{vec}(\widehat{\textbf{Y}}')\) representation). |
W |
Covariance matrix used for reconciled forecasts (\(\mbox{vec}(\widehat{\textbf{Y}})\) representation). |
nn_check |
Number of negative values (if zero, there are no values below zero). |
rec_check |
Logical value: |
varf (type="direct") |
(\(n \times (k^\ast + m)\)) reconciled forecasts variance matrix for \(h=1\), \(\mbox{diag}(\mathbf{MW}\)). |
M (type="direct") |
Projection matrix (projection approach). |
G (type="S" and type="direct") |
Projection matrix (structural approach, \(\mathbf{M}=\mathbf{S}\mathbf{G}\)). |
S (type="S" and type="direct") |
Cross-temporal summing matrix (\(\widetilde{\textbf{F}}\mbox{vec}(\widehat{\textbf{Y}}')\) representation). |
info (type="osqp") |
matrix with some useful indicators (columns)
for each forecast horizon \(h\) (rows): run time ( |
References
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., and Girolimetto, D. (2023), Cross-temporal forecast reconciliation: Optimal combination method and heuristic alternatives, International Journal of Forecasting, 39(1), 39-57.
Girolimetto, D., Athanasopoulos, G., Di Fonzo, T., & Hyndman, R. J. (2023), Cross-temporal Probabilistic Forecast Reconciliation, doi:10.48550/arXiv.2303.17277.
Schä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ä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. (2020). OSQP: An Operator Splitting Solver for Quadratic Programs, Mathematical Programming Computation, 12, 4, 637-672.
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.
See Also
Other reconciliation procedures:
cstrec()
,
ctbu()
,
htsrec()
,
iterec()
,
lccrec()
,
tcsrec()
,
tdrec()
,
thfrec()
Examples
data(FoReco_data)
obj <- octrec(FoReco_data$base, m = 12, C = FoReco_data$C,
comb = "bdshr", res = FoReco_data$res)