Kalman

Kalman — The Kalman filter

Functions

Types and Values

typedef kalman

Includes

#include <gretl/libgretl.h>
#include <gretl/kalman.h>

Description

Functions

kalman_new_minimal ()

kalman *
kalman_new_minimal (gretl_matrix *M[],
                    int copy[],
                    int nmat,
                    int dkvar,
                    int *err);

kalman_free ()

void
kalman_free (kalman *K);

kalman_new ()

kalman *
kalman_new (gretl_matrix *a,
            gretl_matrix *P,
            gretl_matrix *T,
            gretl_matrix *BT,
            gretl_matrix *ZT,
            gretl_matrix *HH,
            gretl_matrix *GG,
            gretl_matrix *y,
            gretl_matrix *x,
            gretl_matrix *mu,
            gretl_matrix *V,
            int *err);

Allocates and initializes a Kalman struct, which can subsequently be used for forecasting with kalman_forecast().

Parameters

a

r x 1 initial state vector.

 

P

r x r initial precision matrix.

 

T

r x r state transition matrix.

 

BT

n x k matrix of coefficients on exogenous variables in the observation equation, transposed.

 

ZT

n x r matrix of coefficients on the state variables in the observation equation, transposed.

 

VS

r x r contemporaneous covariance matrix for the errors in the state equation.

 

VY

n x n contemporaneous covariance matrix for the errors in the observation equation (or NULL if this is not applicable).

 

y

T x n matrix of observable variable(s).

 

x

T x k matrix of exogenous variable(s). May be NULL if there are no exogenous variables, or if there's only a constant.

 

mu

r x 1 vector of constants in the state transition, or NULL.

 

V

T x n matrix in which to record forecast errors (or NULL if this is not required).

 

err

location to receive error code.

 

Returns

pointer to allocated struct, or NULL on failure, in which case err will receive a non-zero code.


kalman_forecast ()

int
kalman_forecast (kalman *K,
                 PRN *prn);

Generates a series of one-step ahead forecasts for y, based on information in the kalman struct K .

Parameters

K

pointer to Kalman struct.

 

prn

printing apparatus (or NULL).

 

Returns

0 on success, non-zero on error.


kalman_run ()

int
kalman_run (kalman *K,
            PRN *prn,
            int *errp);

is_kalman_bundle ()

int
is_kalman_bundle (gretl_bundle *b);

kalman_smooth ()

gretl_matrix *
kalman_smooth (kalman *K,
               gretlopt opt,
               PRN *prn,
               int *err);

kalman_get_loglik ()

double
kalman_get_loglik (const kalman *K);

Retrieves the log-likelhood calculated via a run of kalman_forecast().

Parameters

K

pointer to Kalman struct.

 

Returns

ll value, or NADBL on failure.


kalman_get_arma_variance ()

double
kalman_get_arma_variance (const kalman *K);

Retrieves the estimated variance for an ARMA model estimated using the Kalman filter.

Parameters

K

pointer to Kalman struct.

 

Returns

sigma-squared value, or NADBL on failure.


kalman_set_initial_state_vector ()

int
kalman_set_initial_state_vector (kalman *K,
                                 const gretl_vector *a);

Resets the initial value of the state vector in a Kalman struct, using the values from a . See also kalman_new().

Parameters

K

pointer to Kalman struct.

 

a

vector of values to set.

 

Returns

0 on success, non-zero on error.


kalman_set_initial_MSE_matrix ()

int
kalman_set_initial_MSE_matrix (kalman *K,
                               const gretl_matrix *P);

Resets the initial value of the MSE matrix in a Kalman struct, using the values from P . See also kalman_new().

Parameters

K

pointer to Kalman struct.

 

P

matrix of values to set.

 

Returns

0 on success, non-zero on error.


kalman_set_arma_ll ()

void
kalman_set_arma_ll (kalman *K);

kalman_attach_data ()

void
kalman_attach_data (kalman *K,
                    void *data);

kalman_get_data ()

void *
kalman_get_data (const kalman *K);

kalman_attach_printer ()

void
kalman_attach_printer (kalman *K,
                       PRN *prn);

kalman_get_printer ()

PRN *
kalman_get_printer (const kalman *K);

Types and Values

kalman

typedef struct kalman_ kalman;