% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/coherent.R
\name{coherent_smat}
\alias{coherent_smat}
\title{Structural (summing) matrix for coherent time series}
\usage{
coherent_smat(data, sparse = FALSE)
}
\arguments{
\item{data}{A data object which contains linearly related coherent structures.}

\item{sparse}{If \code{TRUE}, a sparse matrix (class \code{"dgCMatrix"} from the
\pkg{Matrix} package) is returned. Defaults to \code{FALSE}.}
}
\value{
An \eqn{n \times n_b} matrix (dense or sparse) encoding the
structural relationships among all series.
}
\description{
Constructs the \eqn{n \times n_b} structural matrix \eqn{\mathbf{S}} for a
set of linearly related time series, where \eqn{n} is the total number
of series and \eqn{n_b} is the number of bottom-level series.
}
\details{
Let \eqn{\boldsymbol{b}_t} be the \eqn{n_b}-vector of bottom-level series at
time \eqn{t}, and \eqn{\boldsymbol{a}_t = \mathbf{A}\boldsymbol{b}_t} be the
\eqn{n_a = n - n_b} aggregated series, where \eqn{\mathbf{A}} is the
\eqn{n_a \times n_b} aggregation matrix. The full \eqn{n}-vector of series is
\eqn{\boldsymbol{y}_t = [\boldsymbol{a}_t', \boldsymbol{b}_t']'}, and the
structural matrix satisfies

\deqn{\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
\eqn{\tilde{\boldsymbol{y}}_h = \mathbf{S}\mathbf{G}\hat{\boldsymbol{y}}_h},
where \eqn{\hat{\boldsymbol{y}}_h} are the \eqn{h}-step base forecasts.
Optimal reconciled forecasts use
\eqn{\mathbf{G} = (\mathbf{S}'\mathbf{W}^{-1}\mathbf{S})^{-1}\mathbf{S}'\mathbf{W}^{-1}},
with \eqn{\mathbf{W}} a positive definite weight matrix (see
\code{\link[=min_trace]{min_trace()}}).
}
\examples{
tsibble::tourism \%>\% 
  aggregate_key(Purpose, Trips = sum(Trips)) \%>\%
  coherent_smat()

}
\references{
Hyndman, R. J., & Athanasopoulos, G. (2022). \emph{Notation for forecast
reconciliation}. \url{https://robjhyndman.com/hyndsight/reconciliation-notation.html}
}
\seealso{
\code{\link[=coherent_cmat]{coherent_cmat()}} for the corresponding zero-constraint matrix
\eqn{\mathbf{C}} and \code{\link[=aggregate_key]{aggregate_key()}} for computing cross-sectional
aggregations with tsibble data sets.
}
