Model Core: UCM, State-Space, and Kalman Filtering
Track 2 - This Solution · Module 2.3
Experienced+
Course home
Learning ObjectivesModule 2.3 · ~40 min
Explain, at a conceptual level, why this program models sales as a structural time series (trend + seasonal + cyclical + irregular) rather than a plain OLS fit or a Bayesian MMM stack.
Recognize and use the vocabulary: state equation, observation equation, Kalman gain, dynamic regression coefficients, innovations.
Follow how the Kalman filter's prediction/update loop produces a log-likelihood, and why that enables AIC/BIC model comparison.
Why a structural time-series model at all

This is the deep-dive module. If you are an experienced hire arriving from a Bayesian MMM background (Meridian, Robyn, LightweightMMM), read it first - it is where this program's engine differs most from what you know. If you are a fresh analyst, aim to recognize the vocabulary, not to derive the filter; treat the math as reference.

A brand's weekly sales series is not a flat line plus media bumps. It carries a slow-moving trend (the brand growing or fading), seasonal rhythm (festive quarters, summer categories), medium-term cycles that are not strictly periodic, and plain noise. Plain OLS forces one fixed intercept onto all of that: whatever the intercept cannot absorb leaks into the media coefficients, and the model happily "explains" a rising brand trend as media effect. The industry's Bayesian MMM stacks attack the same problem differently - priors over coefficients, posterior sampling - at the cost of a prior-elicitation burden and less interpretable baseline structure.

This program's engine takes the structural route: an Unobserved Components Model (UCM), also known as structural time-series modelling. Instead of treating the series as a black box, UCM explicitly models the underlying structure - each component is a latent (unobserved) variable, and the model estimates how the components evolve over time. The payoffs the methodology workbook names: interpretability (you can see how much variation is trend vs seasonality vs media), flexibility (handles missing data and structural breaks), and robust forecasting. And the baseline the UCM separates out is not a by-product - it is the very quantity the LT model family re-opens and splits into brand-health pillars (module 2.1).

What the UCM sees: one series, four components
Synthetic 3-year weekly sales series decomposed into the pieces the state-space model estimates.
Why this matters for MMM
The slow-moving trend is where long-term brand strength lives; the seasonal component absorbs the recurring annual pattern so media does not get credit for Christmas; what remains after trend, season, and the regression drivers is the irregular term. Because these components are estimated jointly with the media coefficients, the model can separate a slow brand-health drift from a fast promotional spike - the core advantage over a plain static regression.
The decomposition

The canonical UCM writes the observed series as a sum of unobserved components:

y_t = mu_t + gamma_t + psi_t + epsilon_t
observed series = trend + seasonal + cyclical + irregular
  • y_t - the observed time series (weekly sales volume)
  • mu_t - the trend: long-term progression of the level
  • gamma_t - the seasonal component: repeating periodic fluctuations
  • psi_t - the cyclical component: medium-term oscillations that are not strictly periodic
  • epsilon_t - the irregular component: white noise, the randomness nothing else explains

Each component is estimated, not assumed constant. That single fact is what lets the model tell a slow brand-health drift apart from a fast promotional spike sitting on top of it.

State equation vs observation equation

To estimate latent components, the UCM is cast in state-space form - two equations with two distinct jobs. The workbook's teaching case is the local level regression: a regression whose intercept (level) is allowed to wander over time.

Observation equation:   y_t = mu_t + x_t' · beta + epsilon_t
what you SEE: observed sales = current level + regression effects of predictors (media, promo) + observation noise, epsilon_t ~ N(0, sigma²)
State equation:   mu_t = mu_(t-1) + eta_t
how the HIDDEN state MOVES: today's level = yesterday's level + a small random step, eta_t ~ N(0, q)

Read them as a division of labour: the local level mu_t soaks up slow-moving changes in the baseline (underlying market trend, demand shifts), while the regression part x_t' beta captures the effect of predictors - advertising spend, promotions. Because the level is free to move, it cannot be confused with media effects, and vice versa. The coefficients beta may be fixed, or themselves modelled as time-varying states - that is what dynamic regression coefficients means: a coefficient promoted into the state vector so its evolution is estimated too.

The Kalman filter: predict, then update

The Kalman filter is the algorithm that recursively estimates the hidden state from noisy observations - optimal when the system is linear and all noise is Gaussian (Gaussian noise is what lets the filter describe uncertainty fully with a mean and a variance, apply Bayesian updating in closed form, and keep the state's posterior Gaussian at every step). It walks the series one period at a time, and at each period does two things:

  • Prediction step: before seeing this week's sales, predict the state from the last one - for the local level, the best guess for mu_t is simply mu_(t-1) - and widen the uncertainty to admit that the state may have drifted.
  • Update step: now look at the actual observation y_t. Compute the surprise (how far the observation landed from the prediction), then move the state estimate part-way toward the observation. How far it moves is governed by the Kalman gain.

The Kalman gain, in words, is a trust ratio: it compares how uncertain the model is about its own prediction against how noisy observations are known to be. When the prediction is shaky and the data is clean, the gain is high and the new observation pulls the estimate strongly. When the prediction is confident and the data is noisy, the gain is low and the observation barely nudges it. Formally, for the local level:

K_t = P_(t|t-1) / (P_(t|t-1) + sigma_epsilon²)    mu_hat_(t|t) = mu_hat_(t|t-1) + K_t · (y_t - mu_hat_(t|t-1))
gain = prediction variance over total variance; new estimate = prediction + gain times the surprise

Beyond estimating the level, the workbook flags two practical bonuses in the state-space regression setting: missing data is handled naturally (the filter simply skips the update step for a missing week and carries the prediction forward), and the filter cleanly separates signal from noise (state vs observation error).

The client-facing translation of all this machinery: "the model maintains a running, self-correcting estimate of where the brand's baseline is each week, so media effects are measured against a moving baseline rather than a fixed average."
From innovations to a log-likelihood (and AIC/BIC)

The filter also yields the model's fit measure for free. At each step, the one-step-ahead prediction error is called the innovation, v_t = y_t - y_hat_(t|t-1), with variance F_t. Because innovations are Gaussian under the model, they assemble directly into the log-likelihood:

log L(theta) = -1/2 · SUM over t of [ log(2·pi) + log(F_t) + v_t² / F_t ]
theta = the noise variances (sigma_epsilon², sigma_eta²); maximizing this fits the model

Three uses, per the workbook: model fitting (maximize the log-likelihood to estimate the noise variances), model comparison (compute AIC/BIC from the log-likelihood to compare candidate state-space specifications), and forecast evaluation (lower log loss = better predictive performance). When module 2.6's priority_order ranks candidate models on MAPE, adjusted R² and residual diagnostics, this likelihood machinery is what sits underneath the candidates being ranked.

Where to go deeper

Two standard texts cover this entire family properly: Durbin & Koopman, Time Series Analysis by State Space Methods (the reference text for state-space estimation) and Harvey, Forecasting, Structural Time Series Models and the Kalman Filter (the canonical UCM formulation).

Check with SMEShirsha
Confirm that Harvey's structural time-series (UCM) formulation is the actual academic lineage of the production engine, so the citation can be taught as "where our method comes from" rather than "the nearest textbook".
Check Yourself
In the local level regression, what is the essential difference between the observation equation and the state equation?
Why: that division is the whole idea of state-space form: y_t = mu_t + x_t'beta + epsilon_t maps state to observations, while mu_t = mu_(t-1) + eta_t gives the hidden level its own dynamics. Everything else (Kalman filtering, likelihood) operates on this two-equation structure.
Mid-series, the filter's level estimate is very confident, but this week's sales reading comes from a notoriously noisy panel. What does the Kalman gain do?
Why: the gain is the ratio of prediction uncertainty to total (prediction + observation) uncertainty. Low prediction variance and high observation noise push the ratio toward zero: trust the model, discount the noisy reading. The reverse situation pushes it toward one.
Why does the Kalman filter make AIC/BIC comparison of candidate models possible?
Why: the innovations v_t and variances F_t plug directly into log L(theta) = -1/2 SUM [log(2 pi) + log(F_t) + v_t squared / F_t]. With a likelihood in hand, AIC/BIC follow mechanically, letting you compare state-space specifications on a common scale.
Reflection (not graded)

Explain it to a client in three sentences. Using the decomposition y_t = mu_t + gamma_t + psi_t + epsilon_t, write a three-sentence, jargon-free explanation of why this model can separate a slow brand-health trend from a fast promotional spike. Constraints: no equations, no "Kalman", no "latent". Compare your version with a colleague's - the best ones usually talk about a moving baseline that is tracked week by week, so that anything fast and sharp on top of it must be explained by something else.

Sources
Authored from:
  • MathCo Methodology Understanding_UL.xlsx sheets UCM Theory (the y_t = mu_t + gamma_t + psi_t + epsilon_t decomposition and the why-UCM list), State space model Theory (local level regression, observation/state equations, monthly-sales use case, Gaussian-noise rationale), Kalman Filtering (prediction/update steps, Kalman gain, dynamic coefficients, missing-data handling), Log Loss Function (innovations, log-likelihood, AIC/BIC uses)
  • External reference texts: Durbin & Koopman, Time Series Analysis by State Space Methods; Harvey, Forecasting, Structural Time Series Models and the Kalman Filter (lineage pending SME confirmation, see marker above)
Conceptual module - no client data involved.