[R] Bad points in regression

(Ted Harding) ted.harding at nessie.mcc.ac.uk
Fri Mar 16 13:19:05 CET 2007


On 16-Mar-07 11:56:56, Alberto Monteiro wrote:
> I have a question, maybe it's better to explain by example:
> 
> alpha <- 0.3
> beta <- 0.4
> sigma <- 0.5
> err <- rnorm(100)
> err[15] <- 5; err[25] <- -4; err[50] <- 10
> x <- 1:100
> y <- alpha + beta * x + sigma * err
> ll <- lm(y ~ x)
> plot(ll)
> 
> Now, the graphs clearly show that 15, 25 and 50 are the indexes
> of the bad points. How can I retrieve this information from ll?
> 
> Alberto Monteiro

ll is the output of a linear model fiited by lm(), and so has
several components (see ?lm in the section "Value"), one of
which is "residuals" (which can be abbreviated to "res").

So, in the case of your example,

  which(abs(ll$res)>2)
  15 25 50 

extracts the information you want (and the ">2" was inspired by
looking at the "residuals" plot from your "plot(ll)").

Best wishes,
Ted.

--------------------------------------------------------------------
E-Mail: (Ted Harding) <ted.harding at nessie.mcc.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 16-Mar-07                                       Time: 12:19:02
------------------------------ XFMail ------------------------------



More information about the R-help mailing list