Re: [R] residual plots

From: Greg Snow <>
Date: Tue, 25 Nov 2008 14:33:20 -0700

One simple way is to use na.action=na.exclude rather than na.omit. This will still fit the regression without the missing rows, but if you use the resid function to extract the residuals, it will fill the deleted values with NA so that the vector is the same length (and correctly matches) the original (and therefore the predictor to compare to).

Hope this helps,

Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare

> -----Original Message-----
> From: [mailto:r-help-bounces_at_r-
>] On Behalf Of Matt Scholz
> Sent: Tuesday, November 25, 2008 1:48 PM
> To:
> Subject: [R] residual plots
> I've fit a linear model to my data set using the <lm> function. One of
> the
> outputs of that function is a vector of the residuals. I would like to
> do a
> residual plot of this data versus a predictor variable, but the length
> of
> the residual vector is shorter than the length of the predictor
> variable
> vector. This is because when <lm> computes the residual vector, it
> deletes
> entries that came up NA (and lists these as a vector called na.action).
> Could someone please tell me how I can do a simple scatterplot of
> residuals
> v. predictor variable in an instance such as this? I'm not much of a
> code-jockey and haven't been able to find the right function if it
> exists.
> Thanks,
> Matt
> [[alternative HTML version deleted]]
> ______________________________________________
> mailing list
> PLEASE do read the posting guide
> guide.html
> and provide commented, minimal, self-contained, reproducible code.
______________________________________________ mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code.
Received on Tue 25 Nov 2008 - 21:44:50 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 25 Nov 2008 - 22:30:30 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive