[R] dynlm and lm: should they give same estimates?
Achim Zeileis
Achim.Zeileis at wu-wien.ac.at
Thu Oct 16 00:49:48 CEST 2008
On Wed, 15 Oct 2008, Werner Wernersen wrote:
> Hi,
> I was wondering why the results from lm and dynlm are not the same for
> what I think is the same model.
...because it's not the same model :-)
I haven't looked at this in detail, but:
> set.seed(123456)
> e1 <- rnorm(100)
> e2 <- rnorm(100)
> y1 <- ts(cumsum(e1))
> y2 <- ts(0.6*y1 + e2)
> lr.reg <- lm(y2 ~ y1)
> error <- ts(residuals(lr.reg))
> error.lagged <- error[-c(99, 100)]
This corresponds to a lag of two, hence you need
> dy1 <- diff(y1)
> dy2 <- diff(y2)
> diff.dat <- data.frame(embed(cbind(dy1, dy2), 2))
> colnames(diff.dat) <- c('dy1', 'dy2', 'dy1.1', 'dy2.1')
> ecm.reg <- lm(dy2 ~ error.lagged + dy1.1 + dy2.1,
> data=diff.dat)
> ecm.dynreg <- dynlm(d(y2) ~ L(error) + L(d(y1),1) + L(d(y2),1))
^^^^^^^^
a different lag here.
ecm.dynreg <- dynlm(d(y2) ~ L(error, 2) + L(d(y1),1) + L(d(y2),1))
gives the same results as ecm.reg. (Although looking at this briefly, I
suspect that the specification of ecm.reg should be changed rather than
the other way round.)
hth,
Z
More information about the R-help
mailing list