In astsa, there are
Three Levels of Filtering and Smoothing
more info at
FUN WITH ASTSA
FUN WITH ASTSA
The three levels are called Kfilter0/Ksmooth0
, Kfilter1/Ksmooth1
, Kfilter2/Ksmooth2
.
For various models, each script provides the Kalman filter/smoother, the innovations
and the corresponding variance-covariance matrices, and the value of the innovations likelihood
at the location of the parameter values passed to the script. MLE is then accomplished by calling
the script that runs the filter. The model is specified by passing the model parameters.
Level 0 is for the case of a fixed measurement matrix and no inputs; i.e., if At = A for all t, and there are no inputs, then use the code at level 0. If the measurement matrices are time varying or there are inputs, use the code at a higher level (1 or 2). Many of the examples in the text can be done at level 0. Level 1 allows for time varying measurement matrices and inputs, and level 2 adds the possibility of correlated noise processes. The models for each case are (x is state, y is observation, and t = 1, ..., n):
-
♦ Level 0: xt = Φ xt-1 + wt,
yt = A xt + vt, wt ~ iid Np(0, Q) ⊥ vt ~ iid Nq(0, R) ⊥ x0 ~ Np(μ0, Σ0)
♦ Level 1: xt = Φ xt-1 + Υ ut + wt, yt = At xt + Γ ut + vt, ut are r-dimensional inputs, etc.
♦ Level 2: xt+1 = Φ xt + Υ ut+1 + Θ wt, yt = At xt + Γ ut + vt, cov(ws, vt) = S δst, Θ is p × m, and wt is m-dimensional, etc.
Level 0 - Fixed Measurement Matrices and No Inputs
The call to Kfilter0 is,
Kfilter0(n,y,A,mu0,Sigma0,Phi,cQ,cR)
in fairly obvious notation,
except that cQ
and cR
are the Cholesky-type decompositions of
Q and R. In particular, Q = t(cQ)%*%cQ
and R = t(cR)%*%cR
is all that is required (assuming Q
and R
are valid covariance matrices).
The call to Ksmooth0
is similar.
Level 1 - Varying Measurement Matrices and Inputs
The call to the filter is
Kfilter1(n,y,A,mu0,Sigma0,Phi,Ups,Gam,cQ,cR,input)
,
where A is an array with dim=c(q,p,n)
,
Ups
is Υ [p × r], Gam
is Γ [q × r],
and input
is the matrix of inputs
that has the same row dimension as y (which is n × q, so
input
is n × r; the state dimension is p).
The call to Ksmooth1
is similar. Set Ups
or Gam
or input
to 0 (zero) if you
don't use them.
Level 2 - Varying Measurement Matrices, Inputs and Correlated Noise
The
call to the filter is Kfilter2(n,y,A,mu0,Sigma0,Phi,Ups,Gam,Theta,cQ,cR,S,input)
, which is similar
to Kfilter1
, but that S
must be included. Kfilter2
runs the filter given in Property 6.5.
The call to Ksmooth2
is similar. Set Ups
or Gam
or input
to 0 (zero) if you
don't use them. Also, the Θ matrix was not included in the 2nd edition version of the code. You can use your old code by setting Θ to the identity matrix, diag(1, p)
, where p
is the state dimension.