dlmFilter {dlm}  R Documentation 
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.
dlmFilter(y, mod, debug = FALSE, simplify = FALSE)
y 
the data. 
mod 
an object of class 
debug 
if 
simplify 
should the data be included in the output? 
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
.
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

mod 
The argument 
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 
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 
f 
Time series (or matrix) of onestepahead forecast of the observations. 
The observation variance V
in mod
must be nonsingular.
Giovanni Petris GPetris@uark.edu
Zhang, Y. and Li, X.R., Fixedinterval 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), 116.
http://www.jstatsoft.org/v36/i12/.
Petris, Petrone, and Campagnoli, Dynamic Linear Models with R,
Springer (2009).
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.
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))