October 3, 2026 2:58 am

When it comes to forecasting and understanding dynamic processes—like stock prices, patient health, or even earthquakes—time series models give us powerful tools to uncover patterns in data over time. But what if your data is noisy, partially observed, or affected by hidden factors?

Welcome to the world of State-Space Models and Hidden Markov Models (HMMs)—two elegant and flexible frameworks for handling exactly these kinds of problems.

In this post, we’ll break down what these models are, why they matter, and how they’re used, all in a clear and beginner-friendly way.

What Are State-Space Models?

A State-Space Model helps us model an unseen (latent) process that evolves over time, even if we only observe noisy or incomplete measurements of that process.

Think of it like this:

You’re trying to track someone walking through fog. You can occasionally see their position (imperfectly), but you’re really interested in where they’re headed and how they’re moving.

In math terms:

  • Latent state: θt (what’s really happening)
  • Observed data: yt (what you actually measure)

A basic state-space model has:

  1. A state equation that describes how the hidden state evolves
  2. An observation equation that connects the hidden state to the observed data

Why Use State-Space Models?

  • Your data includes missing values
  • Your observations include measurement error
  • You’re trying to model an underlying process you can’t measure directly
  • You need real-time forecasting

Special Case: The Dynamic Linear Model (DLM)

A DLM is a popular type of state-space model. It assumes that both the hidden states and observed data follow normal distributions and evolve linearly over time.

It’s written like this:

Mathematical equations representing a dynamic linear model in state-space form.

Where:

  • Ft, Gt are known matrices
  • Vt, Wt are variances of the noise

How Do We Use These Models?

1. Filtering

To update our beliefs about the current state based on new data, we use the Kalman Filter here—an efficient algorithm that updates predictions in real time.

2. Smoothing

Looking backward after collecting all data to improve estimates of past states.

3. Forecasting

Predicting future observations using the model.

A Real-World Example: Monitoring Hematocrit in Patients

Suppose you’re tracking the hematocrit level (red blood cell volume) in patients after bone marrow transplants. Due to lab noise, what you observe is:

Mathematical representation of a state-space model equation depicting the relationship between observed data and the latent state.

You can build a model where θj evolves slowly over time:

Mathematical equation for a state-space model with the relationship θj = θj-1 + ωj, where ωj follows a normal distribution N(0,0.2).

This setup lets you:

  • Filter and estimate the current level even with noisy data
  • Forecast future hematocrit levels
  • Smooth out the full trajectory

Hidden Markov Models (HMMs)

While state-space models use continuous hidden states, HMMs assume that the hidden process is discrete — think of it like flipping between a few possible “modes” or “states”.

For example, an asset might switch between:

  • Bull market
  • Bear market
  • Volatile market

Each state has different behavior, but you never directly observe the state—you infer it based on the data.

Formally:

  • Hidden states follow a Markov chain (probability of next state depends only on current state)
  • Observations depend on the hidden state

HMM Applications

  • Finance: market regime switching
  • Speech recognition
  • Earthquake modeling: cluster seismic activity into calm vs. active periods
  • Bioinformatics: sequence DNA states

HMMs vs. State-Space Models

FeatureState-Space ModelHidden Markov Model
Hidden stateContinuousDiscrete
TransitionsLinear (usually)Categorical
ExamplesKalman Filter, DLMRegime-switching models
Toolsdlm (R), pystan, statsmodelsdepmixS4, hmmlearn

Takeaways

  • State-space models are flexible tools for modeling complex, evolving time series.
  • Dynamic Linear Models make real-time updating and forecasting easy.
  • Hidden Markov Models are great for modeling switching behavior in discrete states.
  • These methods power real-world applications in healthcare, finance, engineering, and beyond.

Want to Try It Yourself?

Check out these R packages:

  • dlm for DLM modeling and smoothing
  • depmixS4 for HMMs with categorical or continuous data


Discover more from SolutionShala

Subscribe now to keep reading and get access to the full archive.

Continue reading