
2.3 The Kalman FilterThe Kalman filter is a technique that can be used to recursively estimate unobservable quantities called state variables, {X_{t}}, from an observed time series {Y_{t}}. Many time series models (including the ARMA models) can be cast into a statespace form given by where {Y_{t}} is the time series we observe and {X_{t}} is the state variable. F, G, c, and d are known matrices or vectors, and they can be dependent on time. {W_{t}} and {V_{t}} are independent Gaussian white noise variables with zero mean and covariance matrices and , respectively.
Let be the best linear estimate of X_{t} and P_{ts} be its mean square error, given I_{s}, the information up to time s. Given the initial values , the Kalman filter yields . KalmanFilter[Y_{t} , {_{tt+1}, P_{t1}}, F_{t+1}, G_{t}, Q_{t+1}, R_{t}, c_{t+1}, d_{t}]  give  KalmanFilter[{Y_{m+1}, Y_{m+2}, ..., Y_{T}}, {_{m+1m}, P_{m+1m}}, F, G, Q, R, c, d]  give , ..., if F, G, R, c, and d are time independent 
Kalman filtering. Note that if any one of F, G, Q, R, c, ord is time dependent, F, G, Q, R, c, andd in the input to KalmanFilter shown above should be replaced by {F_{m+2}, F_{m+3}, ..., F_{T+1}}, {G_{m+1}, G_{m+2}, ..., G_{T}}, {Q_{m+2}, Q_{m+3}, ..., Q_{T+1}}, {R_{m+1}, R_{m+2}, ..., R_{T}}, {c_{m+2}, c_{m+3}, ..., c_{T+1}}, and {d_{m+1}, d_{m+2}, ..., d_{T}}, respectively. Note also that if c0 and d0, the last two arguments of KalmanFilter can be omitted.
A fixedpoint Kalman smoother gives the estimated value of the state variable at t based on all the available information up to T, where T>t. The idea is that as new data are made available, we can improve our estimation result from the Kalman filter by taking into account the additional information. KalmanSmoothing[filterresult, F]  "smooth" the result of the Kalman filtering 
Kalman smoothing. KalmanSmoothing gives . The first argument of KalmanSmoothing, filterresult, is the result of KalmanFilter, that is,
, and F is the transition matrix in the above state equation. If F is time dependent, the second argument of KalmanSmoothing should be {F_{m+2}, F_{m+3}, ..., F_{T+1}}.
The Kalman prediction estimates the state variable X_{t+h} based on the information at t, I_{t}. KalmanPredictor[{_{t+1t}, P_{t+1t}}, F, Q, c, h]  give the next h predicted values and their mean square errors 
Kalman predictor. KalmanPredictor[, F, Q, c, h] or KalmanPredictor[,{F _{t+2}, ..., F _{t+h}},{Q _{t+2}, ..., Q _{t+h}},{c _{t+2}, ..., c _{t+h}}] gives the next h predicted values and their mean square errors . Again, the argument c can be omitted if it is always 0.
A simple structural model is the local level model. It is given by The model is in statespace form with F=1, G=1, and c=d=0. Out[3]=  
Out[4]=  
Out[7]=  
Out[9]//Short=  
Out[11]=  
Out[12]=  
Out[13]=  
The Kalman filter can be used to calculate the likelihood function of a time series in statespace form. LogLikelihood[data, init, F, G, Q, R, c, d]  give the logarithm of the Gaussian likelihood of data 
Log likelihood. Out[14]=  
Out[16]=  
