The state-space model consists of two processes -- an observation process
and an unobservable state process
.
Having a sampling of observations made up to time
, denoted as
, we want to find the best estimate of the state
that we denote as
. The particular error covariance
matrix is then denoted
.
Three different problems are recognized due to different relations between
and
:
To determine the best estimate, the Kalman filtering approach uses
the mean squared error (MSE) criterion given as
. According to this criterion the best estimate is the conditional expectation
.
This expectation is generally nonlinear (and usually difficult to find)
and therefore we confine ourselves to linear filters.
Since we assume the orthogonality of
we are able to derive
the desired best linear estimate using techniques of projections onto
Hilbert space generated by the observations
.
As a result we get the Kalman filter equations
![]() |
![]() |
![]() |
|
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
|
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
|
![]() |
![]() |
![]() |
|
![]() |
![]() |
![]() |
Several remarks should be made about the Kalman filter equations. First the
inversion of may be replaced with a pseudoinversion. This is
generally the case in models with
singular. Next, the Kalman filter
is a minimum square error estimator among all linear
estimators but in the case of a Gaussian model it is the minimum square error
estimator among all estimators and
, i.e. the Kalman filter yields
the whole information about the conditional distribution of
(this,
however, does not hold in a general non-Gaussian model where the Kalman
filter yields only information about the first two moments of the conditional
distribution of
).
The Kalman filtration equations are implemented in the quantlet
kfilter
. The input parameters of this quantlet are the
time series to be filtered (possibly multivariate), and the system matrices
of the underlying state-space model. To filtrate the time series ar2
simulated in the first example type the following instructions.
x0 = #(0,0) Sig = #(0,0)~#(0,0) H = 1~0 F = #(0.5,1)~#(-0.3,0) Q = 4 R = #(1,0)~#(0,0) filtered = kfilter(ar2,x0,Sig,H,F,Q,R)
library("plot") orig = vec(1:T)~ar2 filt = vec(1:T)~filtered orig = setmask(orig, "line", "red", "thin") filt = setmask(filt, "line", "blue", "medium") disp = createdisplay(1,1) show(disp,1,1, orig, filt) setgopt(disp,1,1, "title", "AR(2) with noise - filtered")
The quantlet
kfilter
saves the file KFOutPut.dat
into the
XploRe
working directory. This file contains all filtered
state estimates
and their error covariance matrices
and might be used to track the development of the estimations'
errors or for prediction purposes.
The matrices
are vectorized and appended to the state
estimation but each of them may be easily recovered. The values of
and
might be recovered in the
following way:
KFOutPut = read("KFOutPut.dat") dimX = rows(x0) x50 = (KFOutPut[50,1:dimX])' P50 = reshape(KFOutPut[50,dimX+1:dimX+dimX^2],#(dimX,dimX))
Kalman smoothing equations are implemented by the quantlet
ksmoother
.
Its usage is similar to the quantlet
kfilter
. Input parameters consist of the
time series to be smoothed (possibly multivariate) and the system matrices of the
underlying state-space model. In the following sample code the time series ar2
is smoothed and the result is visualized.
smoothed = ksmoother(ar2,x0,Sig,H,F,Q,R) smoot = vec(1:T)~smoothed smoot = setmask(smoot, "line", "blue", "medium") disp = createdisplay(1,1) show(disp,1,1, orig, smoot) setgopt(disp,1,1, "title", "AR(2) with noise - smoothed")