[R] dynamic linear models in R

Gabor Grothendieck ggrothendieck at gmail.com
Thu Mar 22 13:56:18 CET 2007


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



More information about the R-help mailing list