Learn R Programming

dlm (version 1.1-2)

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
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?

Value

  • A list with the components described below. If simplify is FALSE, the returned list has class "dlmFiltered".
  • yThe input data, coerced to a matrix. This is present only if simplify is FALSE.
  • modThe argument mod (possibly simplified).
  • mTime series (or matrix) of filtered values of the state vectors. The series starts one time unit before the first observation.
  • U.CSee below.
  • D.CTogether with U.C, it gives the SVD of the variances of the estimation errors. The variance of $m[t,]-theta[t,]$ is given by U.C[[t]] %*% diag(D.C[t,]^2) %*% t(U.C[[t]]).
  • aTime series (or matrix) of predicted values of the state vectors given the observations up and including the previous time unit.
  • U.RSee below.
  • D.RTogether with U.R, it gives the SVD of the variances of the prediction errors. The variance of $a[t,]-theta[t,]$ is given by U.R[[t]] %*% diag(D.R[t,]^2) %*% t(U.R[[t]]).
  • fTime series (or matrix) of one-step-ahead forecast of the observations.

Warning

The observation variance V in mod must be nonsingular.

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.

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

Run this code
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))

Run the code above in your browser using DataLab