Returns the filtered values for the state space model. In addition, the script returns the evaluation of the likelihood at the given parameter values and the innovation sequence.
Kfilter2(num, y, A, mu0, Sigma0, Phi, Ups, Gam, Theta, cQ, cR,
S, input)
number of observations
data matrix, vector or time series
time-varying observation matrix, an array with dim = c(q,p,n)
initial state mean
initial state covariance matrix
state transition matrix
state input matrix; use Ups = 0
if not needed
observation input matrix; use Gam = 0
if not needed
state error pre-matrix
Cholesky decomposition of state error covariance matrix Q -- see details below
Cholesky-type decomposition of observation error covariance matrix R -- see details below
covariance-type matrix of state and observation errors
matrix or vector of inputs having the same row dimension as y; use input = 0
if not needed
one-step-ahead prediction of the state
mean square prediction error
filter value of the state
mean square filter error
the negative of the log likelihood
innovation series
innovation covariances
last value of the gain, needed for smoothing
Practically, the script only requires that Q or R may be reconstructed as t(cQ)%*%(cQ)
or t(cR)%*%(cR)
, respectively.
http://www.stat.pitt.edu/stoffer/tsa4/
See also http://www.stat.pitt.edu/stoffer/tsa4/chap6.htm for an explanation of the difference between levels 0, 1, and 2.