Type: Package
Title: Compute the Exact Observation Weights for the Kalman Filter and Smoother
Version: 0.1.0
Maintainer: Tim Ginker <timginker@gmail.com>
Description: Computes the exact observation weights for the Kalman filter and smoother, based on the method described in Koopman and Harvey (2003) <www.sciencedirect.com/science/article/pii/S0165188902000611>. The package supports in-depth exploration of state-space models, enabling researchers and practitioners to extract meaningful insights from time series data. This functionality is especially valuable in dynamic factor models, where the computed weights can be used to decompose the contributions of individual variables to the latent factors. See the README file for examples.
License: MIT + file LICENSE
Encoding: UTF-8
Imports: FKF
LazyData: true
URL: https://github.com/timginker/wex
BugReports: https://github.com/timginker/wex/issues
RoxygenNote: 7.3.2
NeedsCompilation: no
Packaged: 2025-05-07 10:46:59 UTC; timgi
Author: Tim Ginker ORCID iD [aut, cre, cph]
Depends: R (≥ 3.5.0)
Repository: CRAN
Date/Publication: 2025-05-09 09:50:02 UTC

Sample Data with 10 Economic Indicators

Description

A dataset containing 10 monthly economic indicators, covering the period from January 2000 to November 2021. All variables have been log-differenced, when necessary, to achieve stationarity.

Usage

indicators

Format

A data frame with 263 rows and 11 variables:

date

Date values (format: YYYY-MM-DD)

total_production

Total industrial production in Israel

retail_revenue

Trade revenue

services_revenue

Service revenue

employment

Employment (excluding absent workers)

export_services

Exports of services

building_starts

Building starts

import_consumer_goods

Imports of consumer goods

import_production_inputs

Imports of production inputs

export_goods

Exports of goods

job_openings

Job openings

Source

Public data from various sources


Exact observation weights for the Kalman filter and smoother.

Description

This function computes the exact observation weights for the Kalman filter and smoother, as described by Koopman and Harvey (2003). The implementation of wex builds upon the existing FKF package (see: https://CRAN.R-project.org/package=FKF).

Usage

wex(a0 = NULL, P0 = NULL, Tt, Zt, HHt, GGt, yt, t)

Arguments

a0

A vector giving the initial value/estimation of the state variable. By default is set to zero.

P0

A matrix giving the variance of a0. By default is a diagonal matrix of 10^6.

Tt

An array giving the factor of the transition equation (see Details).

Zt

An array giving the factor of the measurement equation (see Details).

HHt

An array giving the variance of the innovations of the transition equation (see Details).

GGt

An array giving the variance of the disturbances of the measurement equation (see Details).

yt

An n \times d matrix, where d is the dimension and n is the number of observations. matrix containing the observations. “NA”-values are allowed (see Details).

t

An observation index for which the weights are returned.

Details

State space form

\alpha_{t+1} = T_t \alpha_t + H_t \eta_t,

y_t = Z_t \alpha_t + G_t \epsilon_t,

where y_t represents the observed data (possibly with NA's), and \alpha_t is the state vector.

Value

Weight matrices for filtering (Wt) and smoothing (WtT).

References

Koopman, S. J., & Harvey, A. (2003). Computing observation weights for signal extraction and filtering. Journal of Economic Dynamics and Control, 27(7), 1317-1333.

Examples


# Decompose a local level model (Nile data set)
data(Nile)
y <- Nile
wts <- wex(Tt=matrix(1),
Zt=matrix(1),
HHt = matrix(1385.066),
GGt = matrix(15124.13),
yt = t(y),
t=50)