Why would you want to do this?  Confidence intervals tell you about the 
uncertainty of the mean of y give x, not the individual data points.  It may 
make more sense to use prediction intervals that tell you about individuals 
rather than means, but that still means throwing away alpha% of legitimate data.

There are packages and functions for various types of robust regression that 
may be better for what you are trying to accomplish (but I am just guessing 
until you tell us what your really trying to do).

If you really want to do this comparison, just use the predict function on the 
original data to get a confidence (or prediction) interval for each point, then 
compare each point to the corresponding interval (comparison is vectorized, 
this is a single step).

Your code below is filled with redundancies, you may want to brush up on the 
documentation and/or tutorials.

Hope this helps,

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


> -----Original Message-----
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
> project.org] On Behalf Of Keun-Hyung Choi
> Sent: Friday, August 13, 2010 11:42 AM
> To: r-help@r-project.org
> Subject: [R] subsetting data points within confidence limit
> 
> Dear R-list
> 
> 
> 
> Suppose I have a data set stored in hmet, for which I did get
> confidence
> limit on a linear regression as shown below.
> 
> My question is how I can subset only data points which are within the
> confidence limit.
> 
> 
> 
> Thank you.
> 
> Keun-Hyung
> 
> 
> 
> ---------------------------------------------------------------
> 
> Al=rnorm(100, 3)
> 
> Cd=rnorm(100, 0.2)
> 
> hmet=data.frame(Al=Al, Cd=Cd)
> 
> plot(Al, Cd, xlab="Al", ylab= "Cd", , pch=16)
> 
> cd.lm=lm(Cd~ Al, na.action=na.omit, data= hmet)
> 
> abline(cd.lm$coeff, lty=1)
> 
> xy= data.frame (Al =pretty(hmet$Al, 20))
> 
> yhat=predict(cd.lm, newdata=xy, interval="confidence")
> 
> ci=data.frame(lower=yhat[,"lwr"], upper=yhat[,"upr"])
> 
> lines(xy$Al, ci$lower, lty= 2, lwd=2, col="grey")
> 
> lines(xy$Al, ci$upper, lty=2, lwd=2, col="grey")
> 
> 
>       [[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help@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@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.

Reply via email to