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: times
See also: kfilter ksmoother

Quantlet: kem
Description: Calculates estimates of mu, F, Q and R in a state-space model using EM-algorithm. The state-space model is assumed to be in the following form: y_t = H x_t + v_t x_t = F x_t-1 + w_t x_0 ~ (mu,Sig), v_t ~ (0,Q), w_t ~ (0,R)

Reference(s):

Usage: {Estmu, EstF, EstQ, EstR} = kem(y,mu,Sig,H,F,Q,R,LoopLimit)
Input:
y T x m matrix of observed time series, T is the number of observations, m is the dimension of time series
mu n x 1 vector, an initial value for iterations
Sig n x n covariance matrix of the initial state
H m x n matrix
F n x n matrix, an initial value for iterations
Q m x m variance-covariance matrix, an initial value for iterations
R n x n variance-covariance matrix, an initial value for iterations
Looplimit integer; number of iterations (loops of the EM- algorithm)
Output:
Estmu n x 1 vector, the estimate of the mean of the initial state
EstF n x n matrix, the estimate of the state transition matrix
EstQ m x m matrix, the estimate of the covariance matrix
EstR n x n matrix, the estimate of the covariance matrix

Example:
library("xplore")
library("times")
library("plot")
serie = read("kalman2.dat")
y = serie[,2]
mu = #(0,0)
T = 100
Sig = #(0,0)~#(0,0)
H = #(1,0)'
F = #(5,1)~#(1,5)
R = #(1,0)~#(0,1)
Q = 10
{Estmu, EstF, EstQ, EstR} = kem(y,mu,Sig,H,F,Q,R,10)
Estmu
EstF
EstQ
EstR
smoothed = ksmoother(y,Estmu,Sig,H,EstF,EstQ,EstR)
orig = vec(1:T)~y
smoot = vec(1:T)~smoothed
orig = setmask(orig, "line", "red", "thin")
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 - EM estimated")

Result:
Original series is displayed with red colour,
filtered series is displayed with blue colour.
(y is an AR(2) process with errors.)

Contents of Estmu

[1,] -0.046662
[2,]  0.010706

Contents of EstF

[1,]  0.69874  0.11351
[2,]  0.80701   4.0498

Contents of EstQ

[1,]   3.9154

Contents of EstR

[1,]  0.19096 -0.017588
[2,] -0.017588  0.81853



Author: P. Franek, R. Schulz, 20020718
(C) MD*TECH Method and Data Technologies, 05.02.2006