Skip to content
Prev 54569 / 398498 Next

Puzzled at lm() and time-series

On Sat, 21 Aug 2004, Ajay Shah wrote:

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

will work, since an explicit call to na.omit does the right thing re 
attributes.  The difference is in the internal code which says

	/* need to transfer _all but dim_ attributes, possibly lost
	   by subsetting in na.action.  */
	for ( i = length(ans) ; i-- ; )
	  	copyMostAttrib(VECTOR_ELT(data, i),VECTOR_ELT(ans, i));

That's wrong in this case.

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.