Reading: Ch 5.5, 6-6.1 - Shumway and Stoffer
State Space Models¶
Now we’re going to discuss state space models, which are an extension of the ideas we’ve talked about so far in class. With state space models, we measure some noisy outputs that are generated by hidden states that evolve over time, also called latent variables.

In ordinary regression, we have , which assumes is a fixed unknown constant (that we will learn through some fitting procedure). But what if drifts or changes over time? For example, what if we have and . This is now a state space model, where the “state” is the time-varying coefficient .
For ARIMA models, we discussed how an AR(1) process is given by . Suppose we don’t observe directly, but we only observe , which is our signal plus some measurement noise. This could be described by a state space model with state equation and observation equation .
Overall, state-space models are characterized by two principles:
There is a hidden or latent process called the state process. This is assumed to be a Markov process - which means the future and past are independent conditional on the present, .
The observations are independent given the states . That is, the dependence among observations is generated by states.
Extension of AR model to VAR¶
Before we get into state space models, we should briefly mention an extension of the AR model to multiple dimensions, which is the VAR model (vector autoregressive model). Everything we’ve talked about so far with AR has been for a single series. Sometimes, however, we may have multiple series that influence each other. For the VAR model, we write:
,
Where is now a vector and is a transition matrix that expresses the dependence of on . You can read more about this in Chapter 5.5 of Shumway and Stoffer. State space models are more general extension of this.
Linear Gaussian Model¶
We can write the basic form of a linear Gaussian state-space model, also called the dynamic linear model (DLM) with the following state equation:
This is an order one, -dimensional vector autoregression where are white Gaussian noise, . At , we start with a normal vector .
is the state transition parameter and is a matrix. This describes the internal dynamics, i.e., how the state at produces the state at
is an fixed input series. This includes any covariates, experimental conditions, interventions, or other aspects you might supply rather than learning from the data. is and controls how those inputs influence the state.
is the state noise and is Gaussian with covariance .
We do not observe this state vector directly, instead we see a linearly transformed version of it with noise added:
Observation equation:
The data vector is -dimensional, which can be or , the state dimension.
is a measurement or observation matrix. This specifies which linear combinations of the state we measure. By allowing to depend on , we can handle things like missing data by dropping rows for time points where measurements are missing.
is measurement noise with covariance
is and lets the inputs affect the observation directly.
So external inputs can influence through either (through the state equation) or (through the observation equation). As a concrete example, say is a person’s true blood pressure, and is the blood pressure measured by a blood pressure cuff. Say a drug was administered at time - this would then change the state equation, because it will modify the actual blood pressure. On the other hand, an input like “which nurse took the reading” or “which blood pressure cuff was used” would belong in the observation equation, since it will affect what the meter reports, but not the underlying physiological cause. is commonly used, so inputs only drive the state. On the other hand might show up when you’re trying to model known measurement artifacts.
Bone marrow transplant example¶
As an example, we can look at changes in different biomedical markers when a cancer patient undergoes a bone marrow transplant. We have three variables:
log(white blood cell count) [WBC] (essential for immune function)
log(platelet) [PLT] (essential for blood clotting)
hematocrit [HCT] (percentage of red blood cells in total blood volume)
These three variables measure distinct aspects of bone marrow function. A transplant is successful when the new marrow is incorporated and starts producing all three of these.
Unfortunately, as is the case with many real-world datasets (especially those with longitudinal follow up), many data points are missing - approximately 40% in this case. The missing values mostly occur after the 35th day. We can use a state space approach to model these three variables and estimate the missing values. Prior work has shown that platelet count at 100 days post transplant is a good indicator of subsequent long term survival, so we may also want to look at this.
We can model these three variables using the state equation:
The diagonal values of the matrix give you how much each marker’s own recent value predicts its next value. For example, near 1 means the marker WBC is highly persistent and changes slowly from day to day. On the other hand a value near 0 would indicate today’s value has little to do with yesterday (which would be strange for blood markers and might signal a problem with the data collection).
The off-diagonal entries are coefficients that show how much yesterdays value of marker predicts today’s value of marker . The matrices thus represent three stacked regressions, for example:
Meaning today’s log(WBC) value is a weighted sum of yesterday’s WBC, platelets, and hematocrit, plus some noise.
is the effect of component 1 yesterday on component 1 today
is the effect of component 2 yesterday on component 1 today
is the effect of component 3 yesterday on component 1 today
is the effect of component 1 yesterday on component 2 today
is the effect of component 2 yesterday on component 2 today
We then have the observation equations , where the matrix is either the identity matrix or zero matrix depending on whether a blood sample was taken on that day.
For such a model, we would fit the unknown values through expectation maximization (EM) or through maximum likelihood methods:
- matrix, 9 parameters
- symmetric state noise covariance matrix (so only 6 parameters, diagonals and one set of off-diagonals)
- symmetric observation noise covariance matrix (so only 6 parameters, diagonals and one set of off-diagonals - often assumed diagonal)
: mean and covariance of initial state ( parameters - may be fixed according to some prior)
- usually fixed as , but may be fit
In python, we can use statsmodels.tsa.statespace to fit these models.
Filtering, smoothing, and forecasting¶
For state space models, we want to estimate our underlying unobserved signal given the data to time . In practice, the steps for the state space models include:
Filtering, where we estimate using measurements up through time (here =)
Prediction/forecasting, where we have and want to estimate new data
Smoothing, where . This allows us to estimate using the entire dataset, including observations after . This can be used to better estimate missing values.
Other examples¶
Estimating global warming/global temperatures from land and sea temperature measurements
Brain computer interfaces (BCI) - we want to infer intended cursor velocity () from brain measurements from 100 electrodes in motor cortex
Health - we want to estimate true blood glucose level from intermittent measurements from a continuous glucose monitor with some sensor drift.
Finance - we want to measure volatility of the S&P500 on day , we observe daily log returns
Advantages of state space models¶
What are the advantages of state space models as opposed to other models we’ve discussed in this class?
They deal well with missing data and don’t require every time point to be observed. You can still get estimates of the latent state for those missing time points.
We can separate process noise from measurement noise. In ARIMA models, we have just one noise term (innovations/shocks). For real scientific applications, we may have noisy sensors where the measurement reading’s error is distinct from underlying noise in the true signal.
We can have time-varying parameters (unlike fixed in a regression model).