Learn R Programming

miscFuncs (version 1.5-9)

KFadvance: KFadvance function

Description

A function to compute one step of the Kalman filter. Embed in a loop to run the filter on a set of data.

Usage

KFadvance(
  obs,
  oldmean,
  oldvar,
  A,
  B,
  C,
  D,
  E,
  F,
  W,
  V,
  marglik = FALSE,
  log = TRUE,
  na.rm = FALSE
)

Value

list containing the new mean and variance, and if specified, the likelihood

Arguments

obs

Y(t)

oldmean

mu(t-1)

oldvar

Sigma(t-1)

A

matrix A

B

column vector B

C

matrix C

D

matrix D

E

column vector E

F

matrix F

W

state noise covariance

V

observation noise covariance

marglik

logical, whether to return the marginal likelihood contribution from this observation

log

whether or not to return the log of the likelihood contribution.

na.rm

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.

Details

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))