This script replaces Ksmooth0
, Ksmooth1
, and Ksmooth2
by combining all
cases. The major difference is how to specify the covariance matrices; in particular,
sQ = t(cQ)
and sR = t(cR)
where cQ
and cR
were used in Kfilter0-1-2
scripts.
The states \(x_t\) are p-dimensional, the data \(y_t\) are q-dimensional, and
the inputs \(u_t\) are r-dimensional for \(t=1, \dots, n\). The initial state is \(x_0 \sim N(\mu_0, \Sigma_0)\).
The measurement matrices \(A_t\) can be constant or time varying. If time varying, they should be entered as an array of dimension dim = c(q,p,n)
. Otherwise, just enter the constant value making sure it has the appropriate \(q \times p\) dimension.
Version 1 (default): The general model is
$$x_t = \Phi x_{t-1} + \Upsilon u_{t} + sQ\, w_t \quad w_t \sim iid\ N(0,I)$$
$$y_t = A_t x_{t-1} + \Gamma u_{t} + sR\, v_t \quad v_t \sim iid\ N(0,I)$$
where \(w_t \perp v_t\). Consequently the state noise covariance matrix is
\(Q = sQ\, sQ'\) and the observation noise covariance matrix is
\(R = sR\, sR'\) and \(sQ, sR\) do not have to be square as long as everything is
conformable. Notice the specification of the state and observation covariances has changed from the original scripts.
NOTE: If it is easier to model in terms of \(Q\) and \(R\), simply input the square root matrices
sQ = Q %^% .5
and sR = R %^% .5
.
Version 2 (correlated errors): The general model is
$$x_{t+1} = \Phi x_{t} + \Upsilon u_{t+1} + sQ\, w_t \quad w_t \sim iid\ N(0,I)$$
$$y_t = A_t x_{t-1} + \Gamma u_{t} + sR\, v_t \quad v_t \sim iid\ N(0,I)$$
where \(S = {\rm Cov}(w_t, v_t)\), and NOT \({\rm Cov}(sQ\, w_t, sR\, v_t)\).
NOTE: If it is easier to model in terms of \(Q\) and \(R\), simply input the square root matrices
sQ = Q %^% .5
and sR = R %^% .5
.
Note that in either version, \(sQ\, w_t\) has to be p-dimensional, but \(w_t\) does not, and
\(sR\, v_t\) has to be q-dimensional, but \(v_t\) does not.