In astsa, there are
Three Levels of Filtering and Smoothing
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 variancecovariance 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 A_{t} = 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: x_{t} = Φ x_{t1} + w_{t},
y_{t} = A x_{t} + v_{t}, w_{t} ~ iid N_{p}(0, Q) ⊥ v_{t} ~ iid N_{q}(0, R) ⊥ x_{0} ~ N_{p}(μ_{0}, Σ_{0})
♦ Level 1: x_{t} = Φ x_{t1} + Υ u_{t} + w_{t}, y_{t} = A_{t} x_{t} + Γ u_{t} + v_{t}, u_{t} are rdimensional inputs, etc.
♦ Level 2: x_{t+1} = Φ x_{t} + Υ u_{t+1} + Θ w_{t}, y_{t} = A_{t} x_{t} + Γ u_{t} + v_{t}, cov(w_{s}, v_{t}) = S δ_{s}^{t}, Θ is p × m, and w_{t} is mdimensional, 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 Choleskytype 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.