A function to compute one step of the Kalman filter. Embed in a loop to run the filter on a set of data.
KFadvance(
obs,
oldmean,
oldvar,
A,
B,
C,
D,
E,
F,
W,
V,
marglik = FALSE,
log = TRUE,
na.rm = FALSE
)
list containing the new mean and variance, and if specified, the likelihood
Y(t)
mu(t-1)
Sigma(t-1)
matrix A
column vector B
matrix C
matrix D
column vector E
matrix F
state noise covariance
observation noise covariance
logical, whether to return the marginal likelihood contribution from this observation
whether or not to return the log of the likelihood contribution.
na.rm logical, whether or not to handle NAs. Defult is FALSE. Set to TRUE if there are any missing values in the observed data.
The model is: (note that Y and theta are COLUMN VECTORS)
theta(t) = A*theta(t-1) + B + C*W (state equation)
Y(t) = D*theta(t) + E + F*V (observation equation)
W and V are the covariance matrices of the state and observation noise. Prior is normal,
N(mu(t-1),Sigma(t-1))
Result is the posterior, N(mu(t),Sigma(t)), together with the likelihood contribution Prob(Y(t)|Y(t-1))