Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

dlmFilter

DLM filtering


Description

The functions applies Kalman filter to compute filtered values of the state vectors, together with their variance/covariance matrices. By default the function returns an object of class "dlmFiltered". Methods for residuals and tsdiag for objects of class "dlmFiltered" exist.

Usage

dlmFilter(y, mod, debug = FALSE, simplify = FALSE)

Arguments

y

the data. y can be a vector, a matrix, a univariate or multivariate time series.

mod

an object of class dlm, or a list with components m0, C0, FF, V, GG, W, and optionally JFF, JV, JGG, JW, and X, defining the model and the parameters of the prior distribution.

debug

if FALSE, faster C code will be used, otherwise all the computations will be performed in R.

simplify

should the data be included in the output?

Details

The calculations are based on the singular value decomposition (SVD) of the relevant matrices. Variance matrices are returned in terms of their SVD.

Missing values are allowed in y.

Value

A list with the components described below. If simplify is FALSE, the returned list has class "dlmFiltered".

y

The input data, coerced to a matrix. This is present only if simplify is FALSE.

mod

The argument mod (possibly simplified).

m

Time series (or matrix) of filtered values of the state vectors. The series starts one time unit before the first observation.

U.C

See below.

D.C

Together with U.C, it gives the SVD of the variances of the estimation errors. The variance of m_t-θ_t is given by U.C[[t]] %*% diag(D.C[t,]^2) %*% t(U.C[[t]]).

a

Time series (or matrix) of predicted values of the state vectors given the observations up and including the previous time unit.

U.R

See below.

D.R

Together with U.R, it gives the SVD of the variances of the prediction errors. The variance of a_t-θ_t is given by U.R[[t]] %*% diag(D.R[t,]^2) %*% t(U.R[[t]]).

f

Time series (or matrix) of one-step-ahead forecast of the observations.

Warning

The observation variance V in mod must be nonsingular.

Author(s)

Giovanni Petris GPetris@uark.edu

References

Zhang, Y. and Li, X.R., Fixed-interval smoothing algorithm based on singular value decomposition, Proceedings of the 1996 IEEE International Conference on Control Applications.
Giovanni Petris (2010), An R Package for Dynamic Linear Models. Journal of Statistical Software, 36(12), 1-16. http://www.jstatsoft.org/v36/i12/.
Petris, Petrone, and Campagnoli, Dynamic Linear Models with R, Springer (2009).

See Also

See dlm for a description of dlm objects, dlmSvd2var to obtain a variance matrix from its SVD, dlmMLE for maximum likelihood estimation, dlmSmooth for Kalman smoothing, and dlmBSample for drawing from the posterior distribution of the state vectors.

Examples

nileBuild <- function(par) {
  dlmModPoly(1, dV = exp(par[1]), dW = exp(par[2]))
}
nileMLE <- dlmMLE(Nile, rep(0,2), nileBuild); nileMLE$conv
nileMod <- nileBuild(nileMLE$par)
V(nileMod)
W(nileMod)
nileFilt <- dlmFilter(Nile, nileMod)
nileSmooth <- dlmSmooth(nileFilt)
plot(cbind(Nile, nileFilt$m[-1], nileSmooth$s[-1]), plot.type='s',
     col=c("black","red","blue"), ylab="Level", main="Nile river", lwd=c(1,2,2))

dlm

Bayesian and Likelihood Analysis of Dynamic Linear Models

v1.1-5
GPL (>= 2)
Authors
Giovanni Petris [aut, cre], Wally Gilks [ctb] (Author of original C code for ARMS)
Initial release
2018-05-30

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.