[R] residual plots

Greg Snow Greg.Snow at imail.org
Tue Nov 25 22:33:20 CET 2008


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
greg.snow at imail.org
801.408.8111


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Matt Scholz
> Sent: Tuesday, November 25, 2008 1:48 PM
> To: r-help at r-project.org
> 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]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list