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)

Parameters Sig and H are assumed known.


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
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.049524 

[2,]  0.011351 

Contents of EstF

[1,]  0.70331  0.11066 

[2,]  0.80357   4.0443 

Contents of EstQ

[1,]   3.6792 

Contents of EstR

[1,]  0.19393 -0.018777 

[2,] -0.018777  0.81767 


Library: times
See also: kfilter ksmoother

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

Author: P.Franek 990507
(C) MD*TECH Method and Data Technologies, 21.9.2000