[R] Puzzled at lm() and time-series
ajayshah at mayin.org
Mon Aug 23 09:43:29 CEST 2004
> > Any idea why? I think both objects are quite conformable (except for
> > an NA, but that should get dropped by lm() by default).
> That's the problem: the row with a NA gets dropped but the tsp atribute
> does not get adjusted.
> BTW, try traceback() when you get an error.
> lm(g.cpi.iw ~ g.wpi, data = na.omit(M))
> I think it was a leap to assume that you could fit linear models to time
> series via lm. ts objects are not mentioned on the help page for lm, are
> they? Another trap is to assume that diff() will be respected by lm.
My general attitude in R is "if it sounds reasonable, then it ought to
work". :-) I did do a toy example (which was there in the previous
post) and that worked fine, so I jumped to the conclusion that the
internals are all conformable.
If OLS regressions involving ts objects is not 'officially' supported,
what is the recommended way of going about them? Is there an "unts()"
operator which will take me back to raw data? I like to call things
ts() because it gives me prettier graphs.
On diff() also, I have an instinctive confidence that you guys will
have touched up everything perfectly, so if
x = ts()
y = ts()
lm(y ~ x)
dx = diff(x,1)
dy = diff(y,1)
lm(dy ~ dx)
should also work perfectly. :-)
Ajay Shah Consultant
ajayshah at mayin.org Department of Economic Affairs
http://www.mayin.org/ajayshah Ministry of Finance, New Delhi
More information about the R-help