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: gkalfilter gkalsmoother gkalarray gkallag

Quantlet: gkalresiduals
Description: Calculates the innovations v_t and the standardized v^s_t residuals for a state space form that is estimated with the Kalman filter. As input, the output from the Kalman filter is needed. See the help to gkalfilter or the tutorial for a thorough discussion of the model.

Link:
Usage: {V,Vs} = gkalresiduals(Y,ca,Ta,Ra,da,Za,Ha,gkalfilOut)
Input:
Y N_max x TIME matrix of observed time series, where N_max is the maximal number of variables observed at any instant t
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 TIME array with observations d_t
Za N_max x K x TIME array with observations Z_t
Ha N_max x N_max x TIME array with covariance matrices H_t
gkalfilOut K x (K+1) x (TIME+1) array with the output of the Kalman filter
Output:
V N_max x TIME matrix with the innovations v_t
Vs N_max x TIME matrix with the standardized residuals v^s_t

Example:
library("kalman")
library("plot")       ; loads the quantlets from plot library
Y  = read("houseprice")
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")
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)
{V,Vs} = gkalresiduals(Y,ca,Ta,Ra,da,Za,Ha,gkalfilOut)
vs     = reshape(Vs,rows(Vs)*cols(Vs))    ; generates a vector of standardized residuals
vs     = paf(vs,1-isNaN(vs))              ; deletes missing values
QQ     = grqqn(vs)                        ; generates a QQ plot
disp   = createdisplay(1,1)
show(disp,1,1,QQ)
setgopt(disp,1,1,"title","Q-Q Plot","border",0)

Result:
Continues the example of gkalfilter. The innovations
and the residuals are calculated with the filter output.
The resulting display shows the normal Q-Q plot for
the standardized residuals.



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