Keywords - Function groups - @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

Library: kalman
See also: gkalarray gkallag gkalsmoother gkalresiduals

Quantlet: gkalfilter
Description: Calculates a filtered time series for a state space model (uni- or multivariate) with time variable system matrices using the Kalman filter. Furthermore, gkalfilter gives the value of the log likelihood function.

Link:
Usage: {gkalfilOut,loglike} = gkalfilter(Y,mu,Sig,ca,Ta,Ra,da,Za,Ha,l)
Input:
Y N_max x TIME matrix of observed time series, N_max is the maximal number of variables observed at any instant t
mu K x 1 vector, the mean of the initial state
Sig K x K covariance matrix of the initial state
ca K x 1 x TIME array with observations c_t
Ta K x K x TIME array with observations T_t
Ra K x K x TIME array with covariance matrices R_t
da N_max x 1 x TIMES array with observations d_t
Za N_max x K x TIMES array with observations Z_t
Ha N_max x N_max x TIMES array with covariance matrices H_t
l set to 1 if the value of the log likelihood function should be displayed. Otherwise, you can omit this variable.
Output:
gkalfilOut K x (K+1) x (TIME+1) array of state space series a_t~P_t. First entry is mu~Sig for t=0.
loglike value of the log likelihood function evaluated with the results of the filter.

Note:

Example:
library("kalman")
library("xplore")    ; loads the quantlets from xplore library
library("plot")      ; loads the quantlets from plot library
Y   = read("houseprice.dat")
mu  = #(33,-13,1,1,1)
Sig = 0.75*unit(5)
ca = gkalarray(Y,#(0.1,0,0,0,0),0,0)
T  =(#(1.4,1)'|#(-0.4,0)')~0*matrix(2,3)|(0*matrix(3,2)~unit(3))
Ta = gkalarray(Y,T,0,0)
Ra = gkalarray(Y,diag(#(0.4,0,0,0,0)),0,0)
da = gkalarray(Y,#(0,0,0),0,0)
Z  = matrix(3)~0*matrix(3,4)
IZ = 0*matrix(3,2)~(#(1:3)'|#(4:6)'|#(7:9)')
XZ = read("housequality.dat")
Za = gkalarray(Y,Z,IZ,XZ)
Ha = gkalarray(Y,2*unit(3),0,0)
{gkalfilOut,loglike} = gkalfilter(Y,mu,Sig,ca,Ta,Ra,da,Za,Ha)
Time  =(1:cols(Y))
T     = rows(Time)
state = reshape(gkalfilOut[1,1,2:(T+1)],#(1,T,1))'
state = Time~state
state = setmask(state,"line","blue","medium")
Y1    = Time~(Y[1,]')
setmaskp(Y1,0,8,5)
Y2    = Time~(Y[2,]')
setmaskp(Y2,0,8,5)
Y3    = Time~(Y[3,]')
setmaskp(Y3,0,8,5)
disp  = createdisplay(1,1)
show(disp,1,1,state,Y1,Y2,Y3)
setgopt(disp,1,1,"title","Kalman filter","xlabel","Time","ylabel","y,a","border",0)
setgopt(disp,1,1,"ylabel","y,a","border",0)

Result:
The filtered common price component (i.e., the first component
of the filtered state vector) is shown as a blue line; the
observations of Y are shown as black dots.



Author: R. Schulz, A. Werwatz, 20021120 license MD*Tech
(C) MD*TECH Method and Data Technologies, 05.02.2006