Hello,

I am trying to generate a confidence interval (90 or 95%) of a regression
line.  This is primarily just for illustration on a scatter plot (i.e. I am
trying to make this
http://www.ast.cam.ac.uk/~rgm/scratch/statsbook/graphics/anima4.gif).

I have been trying to use the predict.lm function, with interval set as
"confidence", but this still seems to be giving me a prediction interval (as
below).  It is giving the interval based on the x value of a given point, as
opposed to the confidence interval of the regression line in general.  Is
predict.lm the correct function to be using, or is there something else more
appropriate?

> predict.lm(test, interval = c("confidence"), level = 0.90)
        fit        lwr       upr
1  4.170807 -0.2171226  8.558738
2  5.807453  2.1283100  9.486597
3  6.625776  3.2397994 10.011753
4  8.262422  5.2795295 11.245315
5  9.080745  6.1821741 11.979317
6  9.899068  6.9954692 12.802667
7  7.444099  4.2947040 10.593495
8 13.172360  9.4577068 16.887014
9 20.537267 13.0143098 28.060224

I have also tried using package 'ggplot' as follows:

>install.packages("ggplot")
>library(ggplot)
>qplot(wt, mpg, data=mtcars, type=c("point","smooth"), method=lm)
(following Hadley Wickham on this help list)

This generates a plot that looks roughly like what I want, but there is some
customizing of the plot that I would prefer to do in the standard 'plot'
function of the 'graphics' package. Also, ggplot does not give me a vector
of the values of the CI themselves, which would be useful to have.

Any help would be very appreciated.

Thanks,
Tim

        [[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.

Reply via email to