octrec | R Documentation |
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).
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)
basef |
(\mjseqnn \times h(k^\ast+m)) matrix of base forecasts to be reconciled, \mjseqn\widehat\mathbfY; \mjseqnn is the total number of variables, \mjseqnm is the highest time frequency, \mjseqnk^\ast is the sum of (a subset of) (\mjseqnp-1) factors of \mjseqnm, excluding \mjseqnm, and \mjseqnh 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, \mjseqnm), or a subset of \mjseqnp factors of \mjseqnm. |
C |
(\mjseqnn_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 (\mjseqnn(k\ast + m) \times n(k^\ast + m)) covariance matrix (Di Fonzo and Girolimetto 2023, Girolimetto et al. 2023), where \mjseqnk^\ast is the sum of (a subset of) (\mjseqnp-1) factors of \mjseqnm (\mjseqnm is not considered) and \mjseqnn is the number of variables:
|
res |
(\mjseqnn \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
\mjseqn(\textbfU'\textbfy = \mathbf0) 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 (\mjseqn\mboxmin(v) > 0 and \mjseqn\mboxmax(v) < n(k^\ast + m)). |
nn |
Logical value: |
nn_type |
"osqp" (default), "KAnn" (only |
settings |
Settings for osqp (object |
bounds |
(\mjseqnn(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:
|
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
\mjsdeqn
\widehat\textbfY_n \times h(k^\ast+m)) =
\left[\beginarrayccccc
\widehat\textbfA^[m] & \widehat\textbfA^[k_p-1] & \cdots &
\widehat\textbfA^[k_2] & \widehat\textbfA^[1]
\widehat\textbfB^[m] & \widehat\textbfB^[k_p-1] & \cdots &
\widehat\textbfB^[k_2] & \widehat\textbfB^[1]
\endarray
\right] \qquad k \in \cal K,
where \mjseqn\cal K is a subset of \mjseqnp factors of \mjseqnm and,
\mjseqn\widehat\textbfB^[k] and \mjseqn\widehat\textbfA^[k]
are the matrices containing the \mjseqnk-order temporal aggregates of the
bts and uts, of dimension (\mjseqnn_b \times h m/k) and
(\mjseqnn_a \times h m/k), respectively.
Let us consider the multivariate regression model
\mjsdeqn\widehat\mathbfY = \mathbfY + \mathbfE ,
where the involved matrices have each dimension
\mjseqn[n \times (k^\ast+m)] and contain, respectively, the base
(\mjseqn\widehat\mathbfY) and the target forecasts
(\mjseqn\mathbfY), and the coherency errors (\mjseqn\mathbfE) for
the \mjseqnn component variables of the linearly constrained time series
of interest. For each variable, \mjseqnk^\ast + m base forecasts are
available, pertaining to all aggregation levels of the temporal hierarchy
for a complete cycle of high-frequency observation, \mjseqnm. Consider
now two vectorized versions of model, by transforming the matrices either
in original form:
\mjsdeqn\mboxvec\left(\widehat\mathbfY\right) =
\mboxvec\left(\mathbfY\right) + \mathbf\varepsilon \; \mbox with
\; \mathbf\varepsilon = \mboxvec\left(\mathbfE\right)
or in transposed form:
\mjsdeqn\mboxvec\left(\widehat\mathbfY'\right) =
\mboxvec\left(\mathbfY'\right) + \mathbf\eta \; \mbox with
\; \mathbf\eta = \mboxvec\left(\mathbfE'\right).
Denote with \mjseqn\mathbfP the \mjseqn[n(k^\ast+m) \times n(k^\ast+m)]
commutation matrix such that
\mjseqn\mathbfP\mboxvec(\mathbfY) = \mboxvec(\mathbfY'),
\mjseqn\mathbfP\mboxvec(\widehat\mathbfY) = \mboxvec(\widehat\mathbfY')
and \mjseqn\mathbfP\mathbf\varepsilon = \bf \eta.
Let \mjseqn\mathbfW = \mathrmE[\mathbf\varepsilon\varepsilon'] be the
covariance matrix of vector \mjseqn\mathbf\varepsilon, and
\mjseqn\mathbf\Omega = \mathrmE[\mathbf\eta\eta'] the covariance matrix of
vector \mjseqn\mathbf\eta. Clearly, \mjseqn\mathbfW and
\mjseqn\mathbf\Omega are different parameterizations of the same
statistical object for which the following relationships hold:
\mjsdeqn\mathbf\Omega = \mathbfP\mathbfW\mathbfP',
\qquad \mathbfW = \mathbfP' \mathbf\Omega\mathbfP .
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:
\mjsdeqn
\tilde\mathbfy= \hat\mathbfy - \mathbf\Omega\mathbfH\left(
\mathbfH'\mathbf\Omega\mathbfH\right)^-1\mathbfH'\hat\mathbfy =
\mathbfM\hat\mathbfy,
where \mjseqn\widehat\mathbfy = \mboxvec(\widehat\mathbfY') is the
row vectorization of the base forecasts matrix \mjseqn\widehat\mathbfY
The alternative equivalent solution (type = "S"
) (following the
structural reconciliation approach by Hyndman et al., 2011) is
\mjsdeqn\widetilde\mathbfy = \widetilde\mathbfS\left(\widetilde\mathbfS'
\mathbf\Omega^-1\widetilde\mathbfS\right)^-1\widetilde\mathbfS'
\mathbf\Omega^-1\widehat\mathbfy = \widetilde\mathbfS\mathbfG\widehat\mathbfy.
where \mjseqn\widetilde\mathbfS 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 (\mjseqn\mathbfa) and
upper (\mjseqn\mathbfb) bounds like \mjseqn\mathbfa \leq
\widetilde\mathbfy \leq \mathbfb, where \mjseqn\widehat\mathbfy =
\mboxvec(\widehat\mathbfY'), such that:
\mjsdeqn \beginarrayc
a_1 \leq \widetildey_1 \leq b_1
...
a_n(k^\ast + m) \leq \widetildey_n(k^\ast + m) \leq b_n(k^\ast + m)
\endarray \Rightarrow
\mboxbounds = [\mathbfa \; \mathbfb] =
\left[\beginarraycc
a_1 & b_1
\vdots & \vdots
a_n(k^\ast + m) & b_n(k^\ast + m)
\endarray\right],
where \mjseqna_i \in [- \infty, + \infty] and \mjseqnb_i \in [- \infty, + \infty].
If \mjseqny_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)
If the parameter keep
is equal to "recf"
, then the function
returns only the (\mjseqnn \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 |
(\mjseqnn \times h(k^\ast + m)) reconciled forecasts matrix, \mjseqn\widetilde\textbfY. |
Omega |
Covariance matrix used for reconciled forecasts (\mjseqn\mboxvec(\widehat\textbfY') representation). |
W |
Covariance matrix used for reconciled forecasts (\mjseqn\mboxvec(\widehat\textbfY) representation). |
nn_check |
Number of negative values (if zero, there are no values below zero). |
rec_check |
Logical value: |
varf (type="direct" ) |
(\mjseqnn \times (k^\ast + m)) reconciled forecasts variance matrix for \mjseqnh=1, \mjseqn\mboxdiag(\mathbfMW). |
M (type="direct" ) |
Projection matrix (projection approach). |
G (type="S" and type="direct" ) |
Projection matrix (structural approach, \mjseqn\mathbfM=\mathbfS\mathbfG). |
S (type="S" and type="direct" ) |
Cross-temporal summing matrix (\mjseqn\widetilde\textbfF\mboxvec(\widehat\textbfY') representation). |
info (type="osqp" ) |
matrix with some useful indicators (columns)
for each forecast horizon \mjseqnh (rows): run time ( |
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, \Sexpr[results=rd]{tools:::Rd_expr_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.
Other reconciliation procedures:
cstrec()
,
ctbu()
,
htsrec()
,
iterec()
,
lccrec()
,
tcsrec()
,
tdrec()
,
thfrec()
data(FoReco_data)
obj <- octrec(FoReco_data$base, m = 12, C = FoReco_data$C,
comb = "bdshr", res = FoReco_data$res)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.