22
$\begingroup$

Does anybody have a good example for Time Series Forecasting/smoothing using Kalman Filter in R?

$\endgroup$
26
$\begingroup$

Have you looked at Time Series Task View at CRAN?

It lists several entries for packages covering Kalman filtering:

There are also other packages

and possibly more as this is a pretty common techique for time series estimation.

$\endgroup$
15
$\begingroup$

In addition to the packages mentioned in other answers, you may want to look at package forecast which deals with a particular class of models cast in state-space form and package MARSS with examples and applications in biology (see in particular the well-writen manual, Chap. 5).

For general applications, I aggree, though, with the previous answers, with dlm being in my view a versatile and powerful package (well described in the book Dynamic Linear Models in R, by Petris et al.), KFAS offering routines which implement most of the algorithms described in the excellent Time Series Analysis by State Space Methods and FKF with limited facilities and no examples, but being the fastest.

$\endgroup$
  • 1
    $\begingroup$ Thanks all, the book Dynamic Linear Models in R, by Petris et al has high S/N ratio. $\endgroup$ – Aaron Nov 8 '10 at 20:15
7
$\begingroup$

For good examples look at the dlm vignette I would avoid all the other packages if you don't have a clear idea of what you want to do and how.

$\endgroup$
  • 2
    $\begingroup$ +1, I always recommend dlm and its vignette. The bottom line is that DLM's are much more like programming than most other methods. If you intend to do anything beyond basic modeling and forecasting, you will have to understand the matrices (state space programs in some sense) and methods that dlm is generating for you. Most other packages handle the processing of your matrices but expect you to understand how to make them. $\endgroup$ – Wayne Sep 27 '11 at 14:19
5
$\begingroup$

The package stsm is now available on CRAN. The package offers some utilities to fit the basic structural time series model.

The packages mentioned in other answers provide flexible interfaces to cast a broad range of time series models in state-space form and give sound implementations of the Kalman filter. However, in my view, little attention is given to the procedure that optimizes the likelihood function. A general purpose algorithm --the L-BFGS-B algorithm-- is typically used. The stsm package enhances the standard procedure and provides specific algorithms to fit the basic structural model.

Further details are given in the the document provided with the package. For a quick example you can also see this post.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.