Hi all, I've just started working my way through Mike West and Jeff Harrison's _Bayesian Forecasting and Dynamic Models_, and I was wondering if there were any publically-available packages to handle dynamic linear models, as they describe. I found the "dynlm" package, but either I don't yet understand what's going on or that package uses a different sense of the phrase "dynamic linear model." I would expect a fit of a dynamic linear model to produce a time series of parameter estimates, not just single coefficients as that function seems to generate. Could anyone help me understand what's going on here? Thanks, Johann P.S. What I really want to do is fit a linear regression of the form dz_t ~ 0 + dx_t + dy_t, but where the coefficients of dx and dy are allowed to slowly evolve over time. DLMs seem appropriate to this, but I'm open to any other suggestions, as I've not found much support for DLMs in R.
On Wed, 2007-03-21 at 23:58 -0400, Johann Hibschman wrote:> Hi all, > > I've just started working my way through Mike West and Jeff Harrison's > _Bayesian Forecasting and Dynamic Models_, and I was wondering if > there were any publically-available packages to handle dynamic linear > models, as they describe.Johann, The one I'm most familiar with is package dlm by Giovanni Petris. There is also package sspir by Claus Dethlefsen and S?ren Lundbye-Christensen. Both packages are on CRAN. I have been using dlm for some recent DLM analysis I was doing and have found it reasonably easy to use and the maintainer, Giovanni Petris, has been extremely patient and helpful with the odd question I have had about how to specify the models I wanted in dlm. sspir has a formula interface so it may be easier to specify models in it than dlm, but I have no experience of sspir in use. HTH G -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Gavin Simpson [t] +44 (0)20 7679 0522 ECRC [f] +44 (0)20 7679 0565 UCL Department of Geography Pearson Building [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street London, UK [w] http://www.ucl.ac.uk/~ucfagls/ WC1E 6BT [w] http://www.freshwaters.org.uk/ %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
Package dynlm (and dyn) are used to align the time series in the dependent and independent portions of the equations so that one can perform regressions on lagged and differenced versions of the dependent and independent variables. They compensate for the fact that lm (and in the case of dyn lm, glm, rq and others) do not align time series. library(dyn) set.seed(1) z <- ts(rnorm(25)) # this does NOT work since time series are not aligned lm(z ~ lag(z, -1)) # regress z on lagged version of itself - ok dyn$lm(z ~ lag(z, -1)) On 3/21/07, Johann Hibschman <johannh at gmail.com> wrote:> Hi all, > > I've just started working my way through Mike West and Jeff Harrison's > _Bayesian Forecasting and Dynamic Models_, and I was wondering if > there were any publically-available packages to handle dynamic linear > models, as they describe. > > I found the "dynlm" package, but either I don't yet understand what's > going on or that package uses a different sense of the phrase "dynamic > linear model." I would expect a fit of a dynamic linear model to > produce a time series of parameter estimates, not just single > coefficients as that function seems to generate. > > Could anyone help me understand what's going on here? > > Thanks, > > Johann > > P.S. What I really want to do is fit a linear regression of the form > dz_t ~ 0 + dx_t + dy_t, but where the coefficients of dx and dy are > allowed to slowly evolve over time. DLMs seem appropriate to this, > but I'm open to any other suggestions, as I've not found much support > for DLMs in R. > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >