[R] linear regression, exclude a datum

Uwe Ligges ligges at statistik.tu-dortmund.de
Tue Sep 15 13:05:05 CEST 2009



e-letter wrote:
> On 15/09/2009, Uwe Ligges <ligges at statistik.tu-dortmund.de> wrote:
>>
>> e-letter wrote:
>>> On 14/09/2009, Steve Lianoglou <mailinglist.honeypot at gmail.com> wrote:
>>>> Hi,
>>>>
>>>> On Sep 14, 2009, at 9:47 AM, e-letter wrote:
>>>>
>>>>> Readers,
>>>>>
>>>>> I have been reading the r book (Crawley) and tried to use the
>>>>> influence measures function for linear regression, as described. I
>>>>> have one datum that I wish to show in the graph but exclude from the
>>>>> regression and ab line.
>>>>>
>>>>> x	y
>>>>> 0	5
>>>>> 10	9
>>>>> 20	10
>>>>> 30	19
>>>>> 40	4
>>>>>
>>>>> With the influence measures function I plot the graph but linear
>>>>> regression includes the datum (40,4), which I want to show on the
>>>>> graph but exclude from the linear regression ab line.
>>>>>
>>>>> Is there an alternative package to perform this task please?
>>>> Please post the code you're using to try and do the regression.
>>>>
>>>> I think you simply want to remove the data point when you build the
>>>> regression model, then plot it later after you plot the regression.
>>>>
>>> Correct; below are my commands:
>>>
>>>  x<-c(0,10,20,30)
>>>  y<-c(5,9,12,19)
>>>  fit<-lm(y~x)
>>>  plot(y~x)
>>>  abline(fit)
>>>
>>> I try these commands as explained in section 12 (graphics) of the
>>> introduction manual:
>>
>>
>> Hope this example is not in Crawley's book as you cite it, because you
>> need to make the plot large enough to include the value (40,4) already
>> when you create the plot, e.g., by specifying xlim and ylim.
>>
> No, it is an example I made quickly to post to the mailing list. Which
> section of the manual explains xlim please?


?plot.default and any good book that deals with R graphics.



>> Anyway, I'd rather explude the value from a data.frame as fol#ows:
>>
>> # whole data:
>> dat <- data.frame(x = c(0,10,20,30,40), y = c(5,9,12,19,4))
>> dat
>> plot(y~x, data=dat)
>> # fit the regression without the 5th observation:
>> fit <- lm(y ~ x, data=dat[-5,])
>> abline(fit)
>>
> Thank you. Please advise which section of the introduction manual
> explains how to exclude a datum (the instruction '...dat[-5,]'. One of
> my biggest difficulties is finding the relevant section of the
> manual(s).

The manual "An Introduction to R" (e.g. in section 2.7), and any good 
book about R.

Uwe Ligges




More information about the R-help mailing list