[R] residuals with missing values

Ajay Shah ajayshah at mayin.org
Sat Apr 3 17:16:41 CEST 2004


> hi: sorry to bother you all again.  I am running a simple lm(y~x+z)
> regression, in which some of the observations are missing.
> Unfortunately, the residuals vector from the lm object omits all the
> missing values, which means that I cannot simply do residual
> diagnostics (e.g., plot(y,x)).  Would it not make more sense to have
> the residuals propagate the missing values, so that the residuals
> are guaranteed to have the same length as the variables?
> Alternatively, maybe the residuals() function could do this instead.
> But the documentation is not clear:

I had a similar situation, and Brian Ripley said to me:

  If you have missing data in your data frame and want residuals for
  all observations, you need to use na.action=na.exclude, not the
  default na.omit.

-- 
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 mailing list