In the state-space model framework, the Kalman filter estimates the values of a latent, linear, stochastic, dynamic process based on possibly mismeasured observations. Given distribution assumptions on the uncertainty, the Kalman filter also estimates model parameters via maximum likelihood.

Starting with initial values for states (*x*_{0|0}), the initial state variance-covariance matrix (*P*_{0|0}), and initial values for all unknown parameters (*θ*_{0}), the simple Kalman filter:

Estimates, for

*t*= 1,...,*T*:The 1-step-ahead vector of state forecasts vector for period

*t*($${\widehat{x}}_{t|t-1}$$) and its variance-covariance matrix ($${P}_{t|t-1}$$)The 1-step-ahead vector of observation forecasts for period

*t*($${\widehat{y}}_{t|t-1}$$) and its estimated variance-covariance matrix ($${V}_{t|t-1}$$)The filtered states for period

*t*($${\widehat{x}}_{t|t}$$) and its estimated variance-covariance matrix ($${P}_{t|t}$$)

Feeds the forecasted and filtered estimates into the data likelihood function

$$\mathrm{ln}p({y}_{T},\mathrm{...},{y}_{1})={\displaystyle \sum _{t=1}^{T}\mathrm{ln}\varphi ({y}_{t};{\widehat{y}}_{t|t-1},{V}_{t|t-1})},$$

where $$\varphi ({y}_{t};{\widehat{y}}_{t|t-1},{V}_{t|t-1})$$ is the multivariate normal probability density function with mean $${\widehat{y}}_{t|t-1}$$ and variance $${V}_{t|t-1}$$.

Feeds this procedure into an optimizer to maximize the likelihood with respect to the model parameters.

*s*-step-ahead, state forecasts are estimates of the states at period *t* using all information (for example, the observed responses) up to period *t* – *s*.

The *m _{t}*-by-1 vector of 1-step-ahead, state forecasts at period

$${\widehat{x}}_{t|t-1}={A}_{t}{\widehat{x}}_{t-1|t-1},$$

where $${\widehat{x}}_{t-1|t-1}$$ is the *m*_{t – 1}-by-1 filtered state vector at period *t* – 1.

At period *t*, the 1-step-ahead, state forecasts have the variance-covariance matrix

$${P}_{t|t-1}={A}_{t}{P}_{t-1|t-1}{A}_{t}^{\prime}+{B}_{t}{B}_{t}^{\prime},$$

where$${P}_{t-1|t-1}$$ is the estimated variance-covariance matrix of the filtered states at period *t* – 1, given all information up to period *t* – 1.

The corresponding 1-step-ahead forecasted observation is $${\widehat{y}}_{t|t-1}={C}_{t}{\widehat{x}}_{t|t-1},$$, and its variance-covariance matrix is $${V}_{t|t-1}=Var\left({y}_{t}|{y}_{t-1},\mathrm{...},{y}_{1}\right)={C}_{t}{P}_{t|t-1}{C}_{t}^{\prime}+{D}_{t}{D}_{t}^{\prime}.$$

In general, the *s*-step-ahead, forecasted state vector is $${x}_{t|t-s}=E\left({x}_{t}|{y}_{t-s},\mathrm{...},{y}_{1}\right)$$. The *s*-step-ahead, vector of state forecasts is

$${\widehat{x}}_{t+s|t}=\left({\displaystyle \prod _{j=t+1}^{t+s}{A}_{j}}\right){x}_{t|t}$$

and the *s*-step-ahead, forecasted observation vector is

$${\widehat{y}}_{t+s|t}={C}_{t+s}{\widehat{x}}_{t+s|t}.$$

State forecasts at period *t*, updated using all information (for example the observed responses) up to period *t*.

The *m _{t}*-by-1 vector of filtered states at period

$${\widehat{x}}_{t|t}={\widehat{x}}_{t|t-1}+{K}_{t}{\widehat{\epsilon}}_{t},$$

where:

$${\widehat{x}}_{t|t-1}$$ is the vector of state forecasts at period

*t*using the observed responses from periods 1 through*t*– 1.*K*is the_{t}*m*-by-_{t}*h*raw Kalman gain matrix for period_{t}*t*.$${\widehat{\epsilon}}_{t}={y}_{t}-{C}_{t}{\widehat{x}}_{t|t-1}$$ is the

*h*-by-1 vector of estimated observation innovations at period_{t}*t*.

In other words, the filtered states at period *t* are the forecasted states at period *t* plus an adjustment based on the trustworthiness of the observation. Trustworthy observations have very little corresponding observation innovation variance (for example, the maximum eigenvalue of *D _{t}D_{t}′* is relatively small). Consequently, for a given estimated observation innovation, the term $${K}_{t}{\widehat{\epsilon}}_{t}$$ has a higher impact on the values of the filtered states than untrustworthy observations.

At period *t*, the filtered states have variance-covariance matrix

$${P}_{t|t}={P}_{t|t-1}-{K}_{t}{C}_{t}{P}_{t|t-1},$$

where $${P}_{t|t-1}$$ is the estimated variance-covariance matrix of the state forecasts at period *t*, given all information up to period *t* – 1.

*Smoothed states* are estimated states at period *t*, which are updated using all available information (for example, all of the observed responses).

The *m _{t}*-by-1 vector of smoothed states at period

$${\widehat{x}}_{t|T}={\widehat{x}}_{t|t-1}+{P}_{t|t-1}{r}_{t},$$

where:

$${\widehat{x}}_{t|t-1}$$ are the state forecasts at period

*t*using the observed responses from periods 1 to*t*– 1.$${P}_{t|t-1}$$ is the estimated variance-covariance matrix of the state forecasts, given all information up to period

*t*– 1.$${r}_{t}={\displaystyle \sum}_{s=t}^{T}\left\{\left[{\displaystyle \prod}_{j=t}^{s-1}\left({A}_{t}-{K}_{t}{C}_{t}\right)\right]{C}_{s}^{\prime}{V}_{s|s-1}^{-1}{\nu}_{s}\right\},$$ where,

*K*is the_{t}*m*-by-_{t}*h*raw Kalman gain matrix for period_{t}*t*.$${V}_{t|t-1}={C}_{t}{P}_{t|t-1}{C}_{t}^{\prime}+{D}_{t}{D}_{t}^{\prime}$$, which is the estimated variance-covariance matrix of the forecasted observations.

$${\nu}_{t}={y}_{t}-{\widehat{y}}_{t|t-1}$$, which is the difference between the observation and its forecast at period

*t*.

*Smoothed state disturbances* are estimated, state disturbances at period *t*, which are updated using all available information (for example, all of the observed responses).

The *k _{t}*-by-1 vector of smoothed, state disturbances at period

$${\widehat{u}}_{t|T}={B}_{t}^{\prime}{r}_{t},$$

where *r _{t}* is the variable in the formula to estimate the smoothed states.

At period *t*, the smoothed state disturbances have variance-covariance matrix

$${U}_{t|T}=I-{B}_{t}^{\prime}{N}_{t}{B}_{t},$$

where *N _{t}* is the variable in the formula to estimate the variance-covariance matrix of the smoothed states.

The software computes smoothed estimates using backward recursion of the Kalman filter.

*s*-step-ahead, forecasted observations are estimates of the observations at period *t* using all information (for example, the observed responses) up to period *t* – *s*.

The *n _{t}*-by-1 vector of 1-step-ahead, forecasted observations at period

$${\widehat{y}}_{t|t-1}={C}_{t}{\widehat{x}}_{t|t-1},$$

where $${\widehat{x}}_{t|t-1}$$ is the *m _{t}*-by-1 estimated vector of state forecasts at period

At period *t*, the 1-step-ahead, forecasted observations have variance-covariance matrix

$${V}_{t|t-1}=Var\left({y}_{t}|{y}_{t-1},\mathrm{...},{y}_{1}\right)={C}_{t}{P}_{t|t-1}{C}_{t}^{\prime}+{D}_{t}{D}_{t}^{\prime}.$$

where $${P}_{t|t-1}$$ is the estimated variance-covariance matrix of the state forecasts at period *t*, given all information up to period *t* – 1.

In general, the *s*-step-ahead, vector of state forecasts is $${x}_{t|t-s}=E\left({x}_{t}|{y}_{t-s},\mathrm{...},{y}_{1}\right)$$. The *s*-step-ahead, forecasted observation vector is

$${\widehat{y}}_{t+s|t}={C}_{t+s}{\widehat{x}}_{t+s|t}.$$

*Smoothed observation innovations* are estimated, observation innovations at period *t*, which are updated using all available information (for example, all of the observed responses).

The *h _{t}*-by-1 vector of smoothed, observation innovations at period

$${\widehat{\epsilon}}_{t}={D}_{t}^{\prime}{V}_{t|t-1}^{-1}{\nu}_{t}-{D}_{t}^{\prime}{K}_{t}^{\prime}{r}_{t+1},$$

where:

*r*and_{t}*ν*are the variables in the formula to estimate the smoothed states._{t}*K*is the_{t}*m*-by-_{t}*h*raw Kalman gain matrix for period_{t}*t*.$${V}_{t|t-1}={C}_{t}{P}_{t|t-1}{C}_{t}^{\prime}+{D}_{t}{D}_{t}^{\prime}$$, which is the estimated variance-covariance matrix of the forecasted observations.

At period *t*, the smoothed observation innovations have variance-covariance matrix

$${E}_{t|T}=I-{D}_{t}^{\prime}\left({V}_{t|t-1}^{-1}-{K}_{t}^{\prime}{N}_{t+1}{K}_{t}\right){D}_{t}.$$

The software computes smoothed estimates using backward recursion of the Kalman filter.

The

*raw Kalman gain*is a matrix that indicates how much to weigh the observations during recursions of the Kalman filter.The raw Kalman gain is an

*m*-by-_{t }*h*matrix computed using_{t}$${K}_{t}={P}_{t|t-1}{C}_{t}^{\prime}{\left({C}_{t}{P}_{t|t-1}{C}_{t}^{\prime}+{D}_{t}{D}_{t}^{\prime}\right)}^{-1},$$

where $${P}_{t|t-1}$$ is the estimated variance-covariance matrix of the state forecasts, given all information up to period

*t*– 1.The value of the raw Kalman gain determines how much weight to put on the observations. For a given estimated observation innovation, if the maximum eigenvalue of

*D*is relatively small, then the raw Kalman gain imparts a relatively large weight on the observations. If the maximum eigenvalue of_{t}D_{t}′*D*is relatively large, then the raw Kalman gain imparts a relatively small weight on the observations. Consequently, the filtered states at period_{t}D_{t}′*t*are close to the corresponding state forecasts.Consider obtaining the 1-step-ahead state forecasts for period

*t*+ 1 using all information up to period*t*. The*adjusted Kalman gain*($${K}_{adj,t}$$) is the amount of weight put on the estimated observation innovation for period*t*($${\widehat{\epsilon}}_{t}$$) as compared to the 2-step-ahead state forecast ($${\widehat{x}}_{t+1|t-1}$$).That is,

$${\widehat{x}}_{t+1|t}={A}_{t}{\widehat{x}}_{t|t}={A}_{t}{\widehat{x}}_{t|t-1}+{A}_{t}{K}_{t}{\widehat{\epsilon}}_{t}={\widehat{x}}_{t+1|t-1}+{K}_{adj,t}{\widehat{\epsilon}}_{t}.$$

*Backward recursion of the Kalman filter* estimates smoothed states, state disturbances, and observation innovations.

The software estimates the smoothed values by:

Setting

*r*_{T + 1}= 0, and*N*_{T + 1}to an*m*-by-_{T}*m*matrix of 0s_{T}For

*t*=*T*,...,1, it recursively computes:*r*(see Smoothed States)_{t}$${\widehat{x}}_{t|T}$$, which is the matrix of smoothed states

*N*(see Smoothed States)_{t}$${P}_{t|T}$$, which is the estimated variance-covariance matrix of the smoothed states

$${\widehat{u}}_{t|T}$$, which is the matrix of smoothed state disturbances

$${U}_{t|T}$$, which is the estimated variance-covariance matrix of the smoothed state disturbances

$${\widehat{\epsilon}}_{t|T}$$, which is the matrix of smoothed observation innovations

$${E}_{t|T}$$, which is the estimated variance-covariance matrix of the smoothed observation innovations

Consider a state-space model written so that the *m* diffuse states (*x _{d}*) are segregated from the

$${\mu}_{0}=\left[\begin{array}{c}{\mu}_{d0}\\ {\mu}_{s0}\end{array}\right]\text{\hspace{0.17em}}\text{\hspace{0.17em}}\text{and}\text{\hspace{0.17em}}\text{\hspace{0.17em}}{\Sigma}_{0}=\left[\begin{array}{cc}{\Sigma}_{d0}& 0\\ 0& {\Sigma}_{s0}\end{array}\right].$$

*μ*_{d0}is an*m*-vector of zeros*μ*_{s0}is an*n*-vector of real numbers*Σ*_{d0}=*κI*, where_{m}*I*is the_{m}*m*-by-*m*identity matrix and*κ*is a positive real number.*Σ*_{s0}is an*n*-by-*n*positive definite matrix.The diffuse states are uncorrelated with each other and the stationary states.

One way to analyze such a model is to set *κ* to a relatively large, positive real number, and then implement the standard Kalman filter (see `ssm`

). This treatment is an approximation to an analysis that treats the diffuse states as if their initial state covariance approaches infinity.

The *diffuse Kalman filter* or *exact-initial Kalman filter*
[56] treats the diffuse states by taking *κ* to ∞. The diffuse Kalman filter filters in two stages: the first stage initializes the model so that it can subsequently be filtered using the standard Kalman filter, which is the second stage. The initialization stage mirrors the standard Kalman filter. It sets all initial filtered states to zero, and then augments that vector of initial filtered states with the identity matrix, which composes an (*m* + *n*)-by-(*m* + *n* + 1) matrix. After a sufficient number of periods, the precision matrices become nonsingular. That is, the diffuse Kalman filter uses enough periods at the beginning of the series to initialize the model. You can consider this period as presample data.

The second stage commences when the precision matrices are nonsingular. Specifically, the initialization stage returns a vector of filtered states and their precision matrix. Then, the standard Kalman filter uses those estimates and the remaining data to filter, smooth, and estimate parameters. For more details, see `dssm`

and [56], Sec. 5.2.

[1] Durbin J., and S. J. Koopman. *Time Series Analysis by State Space Methods*. 2nd ed. Oxford: Oxford University Press, 2012.

`dssm`

| `estimate`

| `estimate`

| `filter`

| `filter`

| `forecast`

| `forecast`

| `smooth`

| `smooth`

| `ssm`