kalmanFilter#

Purpose#

Data filtering algorithm.

Format#

kout = kalmanFilter(y, Z, d, H, T, c, R, Q, a_0, p_0)#
Parameters:
  • yt (px1 matrix) – numerical vector of times series data.

  • Z (pxM matrix) – design matrix.

  • d (px1 matrix) – observation intercept.

  • H (pxp matrix) – observation disturbance covariance.

  • T (mxm matrix) – transition matrix.

  • c (px1 matrix) – state intercept.

  • R (mxr matrix) – selection matrix.

  • Q (rxr matrix) – state disturbance covariance matrix.

  • a_0 (mx1 matrix) – initial prior state mean.

  • p_0 (mxm matrix) – initial prior covariance matrix.

Returns:

kout (struct) –

Instance of a kalmanOut structure. The following members of kout are referencing within this routine:

kout.filtered_state

Matrix, pxT, filtered states.

kout.filtered_state_cov

Array, Txpxp, filtered state covariances.

kout.predicted_state

Matrix, px(T+1), predicted states.

kout.predicted_state_cov

Array, Txpxp, predicted state covariances.

kout.forecast

Matrix, pxT, forecasts.

kout.forecast_error

Matrix, pxT, forecast error.

kout.forecast_error_cov

Array, Txpxp, forecast error covariances.

kout.loglikelihood

Matrix, px(T+1), computed loglikelihood.

Example#

new;
cls;
library tsmt;

// Load data
y = loadd( getGAUSSHome() $+ "pkgs/tsmt/examples/nile.dat");

// Set up state space matrices
sigma_e = 15099;
sigma_n = 1469.1;

// Linear level model
Z = 1;
H = sigma_e;
T = 1;
Q = sigma_n;
R = 1;
d = 0;
c = 0;

// Initial state variables
a_0 = 0;
p_0 = 10e7;

struct kalmanResult rslt;
rslt = kalmanFilter(y', Z, d, H, T, c, R, Q, a_0, p_0);

Remarks#

The kalman filter inputs are based on the state space representation:

  • \(y_t = d_t + Z_t\alpha_t + \epsilon_t\)

  • \(\epsilon_t \sim N(0, H_t)\)

  • \(\alpha_{t+1} = c_t + T_t\alpha_t + R\eta_t\)

  • \(\eta_t \sim N(0, Q_t)\)

where the \(y_t\) equation is known as the observation or measurement equation, and the \(\alpha_t+1\) equation is the transition equation.

Library#

tsmt

Source#

kalman_filter.src