[R] How to Save the residuals of an LM object greater or less than a certin value to an R object?

Jeff Newmiller jdnewmil at dcn.davis.ca.us
Fri Feb 23 05:56:40 CET 2018


Residuals are stored as a numeric vector. The R software comes with a document "Introduction to R" that discusses basic math functions and logical operators that can create logical vectors:

abs( stdresiduals ) > 2.5

It also discusses indexing using logical vectors:

stdresiduals[ abs( stdresiduals ) > 2.5 ]

Note that in most cases it is worth going  the extra step of making your example reproducible [1][2][3] because many problems arise from issues in the data or in code that you don't think is broken. 

[1] http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example

[2] http://adv-r.had.co.nz/Reproducibility.html

[3] https://cran.r-project.org/web/packages/reprex/index.html (read the vignette)
-- 
Sent from my phone. Please excuse my brevity.

On February 22, 2018 8:09:49 PM PST, faiz rasool <faiz7r at gmail.com> wrote:
>Dear list members,
>
>I want to  save residuals above or less than a certain value to an R
>object. I have performed a multiple linear regression, and now I want
>to find out which cases have a residual of above + 2.5 and – 2.5.
>
>Below I provide the R  commands I have used.
>
>Reg<-lm(a~b+c+d+e+f) # perform multiple regression with a as the
>dependent variable.
>
>Residuals<-residuals(reg) # store residuals to an R object.
>stdresiduals<-rstandard(reg) #save the standardized residuals.
>#now I want to type a  command that will save the residuals  of
>certain range to an object.
>
>I realize that by plotting  the data I can quickly  see the  residuals
>outside a certain boundtry, however, I am totally blind, so visually
>inspecting the plot is not possible for me.
>
>Thank you for any help.
>
>Regards,
>Faiz.
>
>______________________________________________
>R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>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