These notes are based on
Meinhold R.J., Singpurwalla N.D., (1983): Understanding the Kalman Filter. The American Statistician, 37, 123–127.
The Kalman Filter provides an efficient recursive estimator for the unobserved state of a linear discrete time dynamical system in the presence of measurement error. Kalman (1960) first introduced the method in the Engineering literature, but it can be understood in the context of Bayesian inference.
Let denote a vector of observed variables at time and let denote the unobserved state variables of the system at time . We wish to conduct inference about the state variables given only the observed data and the structure of a linear model consisting of a measurement equation and a transition equation.
The evolution of the observed variable depends on the state variables through a linear measurement equation
The variable is observed with measurement error which follows the Normal distribution with mean zero and covariance matrix .
The state vector obeys the transition equation
where and are known matrices and captures the influence of effects that are outside the model on the state transition process. The noise terms and are independent. In general and can be time-dependent but for the sake of simplicity the time subscripts are omitted here.
The Kalman Filter is similar in nature to the standard linear regression model. The state of the process corresponds to the regression coefficients, however the state is not constant over time, requiring the introduction of the transition equation.
Let denote the complete history of observed data at time . Our goal is to obtain the posterior distribution of given . We know from Bayes’ Theorem that
The left-hand side is the posterior distribution of . On the second line, the first term is the likelihood of and the second term is the prior distribution of . This equation defines a recursive Bayesian updating relationship.
At time , our knowledge of the system is summarized by the the posterior distribution
where is our previous estimate about the mean of . This process is initialized at time by specifying and .
This follows directly from the properties of the multivariate Normal distribution.
After observing , we can update our knowledge about using the likelihood . Let denote the error in predicting ,
Observing is equivalent to observing since , , and are all known. Thus, (3) becomes
Now, using the measurement equation (1), we can write , and therefore
Now, from Bayes’ Theorem the posterior distribution of satisfies
Once this probability is computed, we can perform another iteration of the recursion by going back to (3).
Calculating the Posterior Distribution
We can calculate the posterior distribution (10) directly by appealing to the properties of the Normal Distribution. Note that
where is given by (6). Conditional on , the distribution of is
To summarize, the posterior distribution of was be calculated recursively by first choosing initial values for and . Then at each period , given the posterior distribution of , with mean and covariance matrix as in (4), we form a prior for with mean and variance as in (5), evaluate the likelihood in (9) given , and then arrive at the posterior in time given by (12).
Using the theoretical derivation as a guide, we can implement the Kalman Filter as a recursive algorithm. Given initialization values and , at time ,
The posterior distribution at time is Normal with mean and covariance matrix .
Form the covariance matrix of the prior distribution,
Calculate the mean of the posterior,
Calculate the variance of the posterior: