Learn R Programming

miscFuncs (version 1.5-9)

KFadvanceAR2: KFadvanceAR2 function

Description

A function to compute one step of the Kalman filter with second order AR state evolution. Embed in a loop to run the filter on a set of data.

Usage

KFadvanceAR2(
  obs,
  oldmean,
  oldermean,
  oldvar,
  oldervar,
  A,
  A1,
  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)

oldermean

mu(t-2)

oldvar

Sigma(t-1)

oldervar

Sigma(t-2)

A

A matrix A

A1

A matrix A1

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) + A1*theta(t-2) + 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. Priors are normal,

N(mu(t-1),Sigma(t-1)) and N(mu(t-2),Sigma(t-2))

Result is the posterior, N(mu(t),Sigma(t)), together with the likelihood contribution Prob(Y(t)|Y(t-1))