[R] Puzzled at lm() and time-series

Prof Brian Ripley ripley at stats.ox.ac.uk
Mon Aug 23 10:07:51 CEST 2004


On Mon, 23 Aug 2004, Ajay Shah wrote:

> > > 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.
> 
> Thanks! :-)
> 
> > BTW, try traceback() when you get an error.
> > 
> > lm(g.cpi.iw ~ g.wpi, data = na.omit(M))
> 
> Will do.
> 
> > 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". :-) 

You get what you pay for, don't forget.  Telling the donor what a free
gift `ought' or `should' do is discourteous at best.


If you want to use lm on time series, do a ts.intersect to create a 
suitable data frame first, then call na.omit.

If you get an error you don't understand, R's debugging facilities will 
help you find what you didn't understand.  Please learn to use them.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list