| To: | <ken.pierce@oregonstate.edu>, <s-news@lists.biostat.wustl.edu> |
|---|---|
| Subject: | Re: regression line confidence interval |
| From: | <Bill.Venables@csiro.au> |
| Date: | Wed, 27 Apr 2005 09:01:52 +1000 |
| Thread-index: | AcVKqziNONrOiWuyTcyZT8LJmBTWfQABTuMw |
| Thread-topic: | [S] regression line confidence interval |
|
S is a programming language, with excellent graphical facilities,
so why not write your own function? Not only are you allowed to
do that, but with S that's what you are supposed to do. It can be
quicker than google....
Here is a very simple first cut that treats the single predictor
case in an obvious way:
showHourglass <- function(x, y) {
dat <- data.frame(x = x, y = y)
fm <- lm(y ~ x, dat)
newdata = data.frame(x = seq(min(x), max(x), length =
500))
pfm <- predict(fm, newdata = newdata, se =
T)
pfm$upper <- pfm$fit + 2*pfm$se
pfm$lower <- pfm$fit - 2*pfm$se
rg <- range(y, pfm$upper, pfm$lower)
plot(x, y, ylim = rg, type = "n")
points(x, y, pch = 1, col = 2)
lines(newdata$x, pfm$upper, lty = 4, col =
3)
lines(newdata$x, pfm$lower, lty = 4, col =
3)
abline(coef(fm))
invisible(fm)
}
Test
drive:
x
<- runif(50, 0, 10)
y
<- x + rnorm(x)
showHourglass(x, y)
This gives the pointwise confidence interval for the mean (using
'2' as the percentage point of the t-distribution). If you want tolerance
intervals (or prediction intervals for a single new observation) you need to be
a bit more clever, but not much.
Extend, generalize, tidy up, submit for others to use...
Easy.
Bill Venables.
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| ||
| Previous by Date: | regression line confidence interval, Pierce, Ken |
|---|---|
| Next by Date: | Logging of history, Glenn . Treacy |
| Previous by Thread: | regression line confidence interval, Pierce, Ken |
| Next by Thread: | Logging of history, Glenn . Treacy |
| Indexes: | [Date] [Thread] [Top] [All Lists] |