Re: [R] residual plots

From: Greg Snow <Greg.Snow_at_imail.org>
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
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.
______________________________________________ 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.
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 https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive