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 gkalfilter gkallag gkalresiduals

Quantlet: gkalsmoother
Description: calculates a smoothed time series for a state space model (uni- or multivariate) using the Kalman smoother. The quantlet gkalsmoother needs a pre-run of gkalfilter.

Link:
Usage: gkalsmoothOut = gkalsmoother(Y,Ta,Ra,gkalfilOut {,ca})
Input:
Y N_max x TIME matrix, observed time series; N_max is the maximal number of variables observed at any time t
Ta K x K x TIME array, observations for T_t
Ra K x K x TIME array, covariance matrices R_t
gkalfilOut K x (K+1) x (TIME+1) array, output of gkalfilter
ca optional K x 1 x TIME array, state constants c_t; default ca = 0*Ta[,1,]
Output:
gkalsmoothOut K x (K+1) x (TIME+1) array, smoothed state space series a_(t|T)~P_(t|T). First entry is for t=0.

Note:

Example:
library("kalman")
library("xplore")     ; loads the quantlets from xplore library
library("plot")       ; loads the quantlets from plot library
Y     = read("houseprice.dat")
Aa    = read("houseAa.dat")
dimAa = read("housedimAa.dat")
Aa    = reshape(Aa',dimAa)
Pa    = read("housePa.dat")
dimPa = read("housedimPa.dat")
Pa    = reshape(Pa',dimPa)
gkalfilOut = Aa~Pa
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)
gkalsmoothOut = gkalsmoother(Y,Ta,Ra,gkalfilOut)
Time  =(1:cols(Y))
T     = rows(Time)
state = reshape(gkalsmoothOut[1,1,2:(T+1)],#(1,T,1))'
state = Time~state
state = setmask(state,"line","red","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 smoother","xlabel","Time")
setgopt(disp,1,1,"ylabel","y,a","border",0)

Result:
The first component of the smoothed state vector is shown as a
red 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