Constructs the \(n \times n_b\) structural matrix \(\mathbf{S}\) for a set of linearly related time series, where \(n\) is the total number of series and \(n_b\) is the number of bottom-level series.

coherent_smat(data, sparse = FALSE)

Arguments

data

A data object which contains linearly related coherent structures.

sparse

If TRUE, a sparse matrix (class "dgCMatrix" from the Matrix package) is returned. Defaults to FALSE.

Value

An \(n \times n_b\) matrix (dense or sparse) encoding the structural relationships among all series.

Details

Let \(\boldsymbol{b}_t\) be the \(n_b\)-vector of bottom-level series at time \(t\), and \(\boldsymbol{a}_t = \mathbf{A}\boldsymbol{b}_t\) be the \(n_a = n - n_b\) aggregated series, where \(\mathbf{A}\) is the \(n_a \times n_b\) aggregation matrix. The full \(n\)-vector of series is \(\boldsymbol{y}_t = [\boldsymbol{a}_t', \boldsymbol{b}_t']'\), and the structural matrix satisfies

$$\boldsymbol{y}_t = \mathbf{S}\boldsymbol{b}_t, \quad \mathbf{S} = \begin{bmatrix} \mathbf{A} \\ \mathbf{I}_{n_b} \end{bmatrix}.$$

Any linear reconciliation method can be written as \(\tilde{\boldsymbol{y}}_h = \mathbf{S}\mathbf{G}\hat{\boldsymbol{y}}_h\), where \(\hat{\boldsymbol{y}}_h\) are the \(h\)-step base forecasts. Optimal reconciled forecasts use \(\mathbf{G} = (\mathbf{S}'\mathbf{W}^{-1}\mathbf{S})^{-1}\mathbf{S}'\mathbf{W}^{-1}\), with \(\mathbf{W}\) a positive definite weight matrix (see min_trace()).

References

Hyndman, R. J., & Athanasopoulos, G. (2022). Notation for forecast reconciliation. https://robjhyndman.com/hyndsight/reconciliation-notation.html

See also

coherent_cmat() for the corresponding zero-constraint matrix \(\mathbf{C}\) and aggregate_key() for computing cross-sectional aggregations with tsibble data sets.

Examples

tsibble::tourism %>% 
  aggregate_key(Purpose, Trips = sum(Trips)) %>%
  coherent_smat()
#>      [,1] [,2] [,3] [,4]
#> [1,]    1    1    1    1
#> [2,]    1    0    0    0
#> [3,]    0    1    0    0
#> [4,]    0    0    1    0
#> [5,]    0    0    0    1