% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/RcppExports.R
\name{kalman_smoother_cpp}
\alias{kalman_smoother_cpp}
\title{Kalman Filter and RTS Smoother (TASC)}
\usage{
kalman_smoother_cpp(Y, W, A, C, Q, R, z0, P0)
}
\arguments{
\item{Y}{Observed data matrix (N x T). Use NA for unobserved entries.}

\item{W}{Observation / loading matrix (N x r)}

\item{A}{State transition matrix (r x r). Pass diag(r) for random-walk dynamics.}

\item{C}{State drift vector (r x 1)}

\item{Q}{State noise covariance (r x r)}

\item{R}{Observation noise covariance (N x N, diagonal in practice)}

\item{z0}{Initial state mean (r x 1)}

\item{P0}{Initial state covariance (r x r)}
}
\value{
A list with z_smooth, P_smooth, P_cross, z_pred, z_upd.
P_cross is an r x r x (T-1) cube. Slice t (C++ 0-indexed, t=0,...,T-2)
stores P(t+1, t | T) (0-indexed), i.e. P(t+2, t+1 | T) in 1-indexed
Shumway-Stoffer notation. Formula: P(t+1|T) * J_t^T (eq. 6.68-6.69).
}
\description{
Implements the Kalman filter (forward pass) and Rauch-Tung-Striebel smoother
(backward pass) for the state-space model in Rho et al. (2026):
}
\details{
State:       z(t+1) = A z(t) + C + eta(t),  eta(t) ~ N(0, Q)
Observation: y_t    = W z_t + eps_t,        eps_t  ~ N(0, R)

Observation rows with NA (treated post-intervention) are automatically
dropped at each time step so only control-unit rows update the filter.

The P update uses the numerically stable Joseph form:
P(t|t) = (I - K W_obs) P(t|t-1) (I - K W_obs)^T + K R_obs K^T
}
