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.

 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:
The state space model has the form:

State equation

alpha_t = c_t + T_t*alpha_t-1 + e^s_t

Measurement equation

y_t = d_t + Z_t*alpha_t + e^m_t

with

alpha_0 ~ (mu,Sig), e^s_t ~ (0,R_t), e^m_t ~ (0,H_t)

All parameters are known.

We denote with as_(t|T) the filtered series of the unobservable state vector alpha_t and with Ps_(t|T) the corresponding covariance matrix. The output of the procedure is an array with as_(t|T) and Ps_(t|T) for all t.

To run the smoother, it is necessary to run gkalfilter first. This produces the array gkalfilOut.

Example:
```library("kalman")
library("xplore")     ; loads the quantlets from xplore library
library("plot")       ; loads the quantlets from plot library
Aa    = reshape(Aa',dimAa)
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
Y1    = Time~(Y[1,]')
Y2    = Time~(Y[2,]')
Y3    = Time~(Y[3,]')
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