The Kalman filter appears in the vault in three places — BSTS / CausalImpact, the linear-Gaussian state-space notes, and probabilistic ODE solvers. What is shared, what differs, and what does seeing them together buy?
Summary
All three are the same algorithm on the same model class: a Markov latent state with local observations, solved by a forward predict/update pass, a backward RTS pass, and a free marginal likelihood from the innovations — i.e. Gaussian-process regression with a Gauss–Markov prior. What differs is what is plugged in: in BSTS the state is trend + seasonality + regression, the data are real noisy sales, and the posterior is extrapolated without updates to give a counterfactual; in an ODE filter the state is the solution and its derivatives, the “data” are self-generated zeros with , and the posterior covariance is a numerical error estimate. Seeing them together gives one notation, portable engineering (square-root filtering, EKF1/IEKS linearisation, innovation-based calibration), a state-space reading of adstock, and — the real prize — a single filter that fuses a mechanistic ODE with observed data.
Answer
1. The shared core (what is genuinely the same idea)
The three clusters cite two books — Särkkä (2013) for the State-Space and Kalman Filter folder and Hennig–Osborne–Kersting for Bayesian Filtering and Smoothing — but state identical mathematics.
- Model. A hidden Markov state and conditionally independent measurements: , (^def-ssm; Def. 5.1 in ^def-markov-chain). These “two properties are exactly what makes the predict/update recursion valid”.
- Forward pass. Chapman–Kolmogorov prediction then Bayes update; in the linear-Gaussian case only move:
Kalman filter ( ^thm-kalman; identical to ^thm-kalman-filter)
- Backward pass. The RTS smoother with gain gives , and except at the endpoint (^thm-rts). The ODE smoothers EKS0/EKS1 use the very same recursion (ODE Filters and Smoothers, Eqs. 38.23–38.25).
- Free marginal likelihood. The update normaliser is , so is a recursive sum of (^thm-energy). The PN book states the same prediction-error decomposition and uses it to calibrate the prior scale (^def-runtime-calibration).
- What it “is”. Filter + smoother return marginals exactly equal to GP regression under the corresponding Gauss–Markov prior, at instead of (^thm-filter-gp-equivalence; Gaussian Process Regression). Discretising a linear SDE supplies and (Gauss-Markov Processes and SDEs).
So “the Kalman filter” is never the model — it is the inference routine for any chain-structured Gaussian model. The content is always in and in what you do with the posterior.
2. Side by side: what plays each role
| Role | Särkkä notes (generic) | BSTS / CausalImpact | Probabilistic ODE filter | Koyck / adstock / TF (synthesis) |
|---|---|---|---|---|
| Notation | (Bayesian Structural Time-Series Model) | (retention), | ||
| State | position + velocity (car tracking) | : level, slope, seasonals, dynamic coefficients | : the solution and derivatives | goodwill / adstock stock ; or time-varying |
| Transition | Wiener-velocity discretisation | block-diagonal: trend, sum-to-zero seasonal matrix, identity for (Local Linear Trend and Seasonality) | -times integrated Wiener process: — a Taylor extrapolation (ODE Filters and Smoothers) | ; return-to-normality |
| Observation | noisy position | : real KPI, carries control series | : a Dirac likelihood on the ODE residual; nonlinear in the state | sales noise (then Hill saturation makes it nonlinear) |
| Where data come from | sensors | the world (pre-period only) | the solver itself, by evaluating at its own predicted mean | the world |
| Observation noise | , learned | recommended (“a positive can absorb linearisation error”) | learned | |
| Linear? | yes | yes given | prediction exact; update linearised: EKF0 () or EKF1 () | linear only before saturation |
| Hyperparameters | MAP / MCMC / EM on , states integrated out | Gibbs: states by Durbin–Koopman simulation smoother, variances by conjugate Gamma, by spike-and-slab (MCMC Inference for CausalImpact) | one scale : quasi-ML , or recursive Gamma update | by GLS / Kalman |
| Posterior used for | denoising (RMSE ) | counterfactual forecast , then (Counterfactual Impact Estimation) | numerical error estimate: , step-size control, uncertainty-aware likelihood | long-run multiplier, carryover attribution |
| Filter or smoother? | both | smoothing inside the pre-period, pure prediction after the intervention | EKS1 by default; EKF1 if only matters | either |
Three observations the table makes visible:
(a) The BSTS trend is nearly the ODE solver’s prior. Synthesis: the local linear trend , has the transition , which is of the once-integrated Wiener process at . The difference is the noise: BSTS takes independent , whereas the exact discretisation gives the correlated — the matrix that appears verbatim in Särkkä’s car-tracking example in Linear-Gaussian State-Space Models. With the BSTS trend is an integrated random walk whose smoothed mean is, by Gaussian Process Regression, a cubic smoothing spline. The AR(1)-slope variant () is the discrete cousin of the integrated Ornstein–Uhlenbeck prior (IOUP) that ODE filters use for decaying solutions.
(b) The same widening band means opposite things. In CausalImpact the post-period is handled by running the filter forward with no update step, so accumulates each step; intervals “widen progressively” because “the local linear trend drifts as a random walk” (Counterfactual Impact Estimation). In an ODE filter the prediction step inflates uncertainty identically — “exactly the intuition of accumulating numerical error between evaluation nodes” (Gauss-Markov Processes and SDEs) — but an update follows at every grid point, so the band contracts at rate (^thm-calib). BSTS uncertainty is about a world that was never observed; ODE-filter uncertainty is about a deterministic quantity not yet computed (the vault flags this as an open philosophical question, §42.7 in Further Topics in ODE Solvers).
(c) States out, or states in. Marginal Likelihood via the Kalman Filter integrates states out and samples from ; MCMC Inference for CausalImpact does the complement — it draws states and then samples variances conditionally, because the spike-and-slab prior breaks the closed form. The ODE filter does neither: it has one hyperparameter and estimates it in closed form from the innovations. All three put an inverse-Gamma on the variance scale ( in BSTS; in PN).
3. What only looks similar
- HSGP vs state-space GPs. Both make GP time-series decompositions cheap, and the birthdays model (trend + annual cycle + weekday, Model Building - Time-Series Decomposition for Birthdays) is the GP twin of BSTS. But HSGP gets from a truncated basis expansion on with kernel-independent basis functions; the Kalman route gets from the Markov property, exactly and only for Gauss–Markov kernels (IWP, Matérn-). HSGP handles the squared-exponential and periodic kernels, works inside HMC with non-Gaussian likelihoods, and is not recursive.
- DeepAR’s hidden state is not a latent state. is a deterministic function of observed inputs, so “in contrast to state space models with latent variables — no inference is required”. There is no filtering, no smoothing, no component you can switch off to form a counterfactual.
- Adstock is a state only in a degenerate sense. Synthesis: geometric adstock (the Koyck recursion of ^def-koyck, equivalently in the Transfer Function Model) is a transition with a known input and zero process noise: given the state is computed, not inferred. The Kalman filter becomes useful only when something stochastic is added — a random-walk or return-to-normality coefficient (which the MRM book says is “estimated via Kalman filter”, and which is BSTS’s dynamic regression with AR(1) instead of random-walk dynamics), or process noise on the goodwill stock. Delayed adstock with window (Carryover (Adstock) Functional Forms) needs an -dimensional shift-register state, structurally like the seasonal block. And sits inside , so it is a parameter learned through the marginal likelihood, never a state.
4. What seeing them together buys
- One implementation, one diagnostic. Standardised innovations should be white and unit-variance in any of these models; the ODE filter’s is literally their mean square. Synthesis: run the same check on a BSTS pre-period before trusting the counterfactual interval.
- Numerical engineering transfers. PN had to solve ill-conditioning ( entries span orders of magnitude) with Nordsieck rescaling and square-root (Cholesky/QR) filtering (Theory of ODE Filters and Smoothers). A BSTS with seasonals plus dynamic regression has the same covariance-conditioning problem.
- A ladder for nonlinearity. The ODE notes supply what the Särkkä folder omits: EKF0 (no Jacobian) → EKF1 → IEKS (MAP, re-linearise to a fixed point) → particle filter for bimodal posteriors (the Bernoulli-ODE bifurcation, which “a Gaussian ODE filter would … miss entirely”). That is the menu for a state-space MMM with a saturating observation equation.
- Filter vs smoother is a question about the estimand. PN: “EKF1 … good if only final-time matters”, EKS1 when the whole path matters. Causal analogue: retrospective decomposition of the pre-period is smoothing; the counterfactual is prediction; real-time monitoring of a live test is filtering.
- Fusing mechanism and data. §41.3 of Further Topics in ODE Solvers: add a linear observation to the ODE state-space model and one EKF1/EKS1 pass infers the solution and a latent GP forcing (the Covid contact-rate example) in linear time. That extended model is precisely a BSTS whose trend block is replaced by mechanistic dynamics.
- Uncertainty-aware likelihoods. When a simulator is fitted to data, the solver’s covariance enters as , which “corrects the overconfidence” of treating the numerical solution as exact.
Practical Implications
Decision rule for a time-series measurement problem
- Is there a latent quantity that evolves stochastically? If not (fixed- adstock, fixed coefficients), you do not need a filter; fit the regression with HMC.
- Linear-Gaussian given hyperparameters, single series, want a counterfactual? BSTS: smooth the pre-period, predict the post-period with no updates, difference. Report the running average for stock KPIs and the cumulative sum only for flows. Expect the interval to grow with horizon — keep test windows short relative to , or use the AR(1) slope.
- Ad effectiveness drifting (wear-out, creative refresh)? Dynamic regression / return-to-normality ; this is the case the MRM literature assigns to the Kalman filter.
- Saturating or count observation? Either EKF1/IEKS-style linearisation or drop the filter and sample states with HMC; if multimodal, particle filter.
- Smooth nonparametric trend + several seasonalities inside a PyMC/Stan model? HSGP rather than a state-space block.
- Thousands of related series, forecast only? DeepAR-style global model; you give up components and counterfactual semantics.
- ABM mean-field or compartmental ODE calibrated to sales? Use an ODE filter so numerical error enters the likelihood, and consider the extended state-space model to infer a latent time-varying rate in one pass.
Checklist whenever a Kalman filter is involved: write down explicitly; decide filter / smoother / predictor from the estimand; check innovation whiteness; use square-root form when the state is large; never read a post-period gap as causal without the placebo backtests linked from Counterfactual Impact Estimation.
Source Notes
Related Concepts
- Single Marketing Time Series — ARIMA models have state-space representations and Kalman-evaluated likelihoods
- Model Building with Latent Variables - Animal Movement — the HMM forward algorithm is the discrete-state analogue of the Kalman recursion
- Approximate Thompson Sampling and Practical Extensions — incremental Laplace is described there as “closely related to an extended Kalman filter”
- Bayesian Quadrature — EKF0/EKS0 reduce to Kalman-form Bayesian quadrature when does not depend on
- Spike-and-Slab Prior for Covariate Selection — why BSTS samples states instead of integrating them out
- Q - Carryover Dynamics and the Timing of Sequential Media Experiments — carryover as a latent state for experiment timing
- Q - Comparing Geo-Test Estimators from TBR to Synthetic DiD — where BSTS sits among geo estimators
Gaps
- No control-input form. Neither filtering cluster writes , so the adstock-as-state mapping in §3 is synthesis, not something a vault note derives. No note gives a state-space MMM.
- Nonlinear / non-Gaussian filtering exists only inside the ODE notes. There is no general note on EKF/UKF, particle filters, or count-valued (Poisson / negative-binomial) state-space models — the Särkkä ingestion stopped at the linear-Gaussian core.
- Durbin–Koopman simulation smoother is named but not derived; its relation to RTS is stated in one sentence.
- State-space ↔ GP duality is asserted in See-Also links of Hilbert Space Gaussian Processes but only proved (for Gauss–Markov priors) in the PN notes; periodic/quasi-periodic kernels in state-space form are not covered.
- The vault does not discuss steady-state gains (, DARE) for BSTS, nor identification assumptions of CausalImpact (controls unaffected by treatment, stable pre-period relationship) in the notes read here.
Follow-Up Questions
- What does a state-space MMM look like — adstock as a controlled state, random-walk channel coefficients, Hill observation — and does EKF1/IEKS beat plain HMC on it?
- Can the extended state-space model of §41.3 calibrate a mean-field ODE approximation of an agent-based market model against weekly sales in one smoothing pass?
- When does a Matérn-3/2 state-space trend give materially different CausalImpact intervals from the local linear trend?
- How should innovation-whiteness diagnostics be combined with placebo backtests to validate a BSTS counterfactual?