KF-interfaces: Kalman Filter

Description Usage Arguments Details Value References See Also Examples

Description

This function provides a unified interface for implementations of the Kalman filter available in different packages.

Usage

1
2
3
4
KalmanFilter(y, ss, 
  KF.version = c("KFKSDS", "StructTS", "KFAS", "FKF", "dlm", "dse"),
  KF.args = list(), check.args = TRUE, debug = FALSE)
make.KF.args(ss, KF.version, KF.args = list())

Arguments

y

a numeric time series or vector.

ss

a list containing the matrices of the state space model.

KF.version

a character string indicating the implementation to be used.

KF.args

a list containing optional arguments to be passed to the function that runs the Kalman filter.

check.args

logical. If TRUE, it is checked that the elements of KF.args are valid for the selected interface KF.version.

debug

logical. Currently ignored.

Details

For some purposes such as testing, debugging or development of extensions, this function provides a useful unified interface for different implementations of the Kalman filter. In a production environment, the use of the original interfaces provided by each package is recommended since they sometimes provide further options or may incorporate further capabilities in the latest updates.

The elements in the argument ss must be named in accordance with the notation given in KF. The function char2numeric in package stsm is a convenient way to create the argument ss for those models already defined in that package.

If KF.args is empty, default values are defined depending on the interface selected in KF.version. The function make.KF.args set default values for those arguments that are explicitly defined in KF.args. It also checks that the arguments passed through KF.args are correct and a warning is given if any of them does not apply to the selected interface KF.version.

Argument KF.version: the option StructTS applies the Kalman filter as in the function StructTS of the stats package. The remaining possible values for this argument are the names of the package that contains the Kalman filter interface.

Notes: (1) The package sppir is no longer maintained on CRAN and is not currently available here as an option. For old versions see sspir.

(2) KF.version="dse" requires manually loading the package dse.

Value

A list containing the output returned by each interface and the value of the negative of the log-likelihood function in the element mloglik.

References

Dethlefsen, C., Lundbye-Christensen, S. and Christensen A. L. (2012) R package version 0.2.10. sspir: State Space Models in R, http://CRAN.R-project.org/package=sspir.

Durbin, J. and Koopman, S. J. (2001). Time Series Analysis by State Space Methods. Oxford University Press.

Gilbert, P. D. (2013) R package version 2013.3-2. dse Brief User's Guide: Dynamic Systems Estimation, http://CRAN.R-project.org/package=dse.

Harvey, A. C. (1989). Forecasting, Structural Time Series Models and the Kalman Filter. Cambridge University Press.

Helske, J. (2012). R package version 0.9.11. KFAS: Kalman Filter and Smoother for Exponential family state space models., http://CRAN.R-project.org/package=KFAS.

Luethi, D., Erb, P. and Otziger, S. (2012) R package version 0.1.2. FKF: Fast Kalman Filter, http://CRAN.R-project.org/package=FKF.

Petris, G. (2013) R package version 1.1-3. dlm An R Package for Dynamic Linear Models, http://CRAN.R-project.org/package=dlm.

See Also

KF; char2numeric in package stsm.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# state space representation of a structural time series model 
# with arbitrary parameter values
require("stsm")
m <- stsm::stsm.model(model = "BSM", y = AirPassengers, transP = "StructTS",
  pars = c("var1" = 30, "var2" = 15, "var3" = 1, "var4" = 12))
ss <- stsm::char2numeric(m)
# value of the likelihood using different interfaces and options
KalmanFilter(y = m@y, ss = ss, KF.version = "KFKSDS", KF.args = list(P0cov = FALSE))$mloglik
KalmanFilter(y = m@y, ss = ss, KF.version = "KFKSDS", KF.args = list(P0cov = TRUE))$mloglik
# 'StructTS' does not include some constants
KalmanFilter(y = m@y, ss = ss, KF.version = "StructTS")$mloglik

Example output

Loading required package: stsm
[1] 916.4979
[1] 857.4643
[1] 5.44563

KFKSDS documentation built on May 2, 2019, 8:51 a.m.