[R-sig-dyn-mod] R-sig-dynamic-models Digest, Vol 80, Issue 1
Thomas Petzoldt
thomas.petzoldt at tu-dresden.de
Thu Dec 18 11:15:01 CET 2014
On 12/17/2014 6:06 PM, Titus Kassem wrote:
> Hi all,
>
> I really want to get prediction interval. I can plot the linear
> regression line, however, I want two other lines, one above and one
> below the regression line. Thank you.
As said, a regression "line" (i.e. a straight line) would not be valid
for your data, because the dependency is non-linear. And please consult
a statistical textbook about the difference between a confidence and a
prediction interval!
Anyway, here a standard example for the linear case, that can be found
in the R help pages, see: ?predict.lm
Thomas
## slightly modified example from predict.lm
x <- rnorm(15)
y <- x + rnorm(15)
predict(lm(y ~ x))
new <- data.frame(x = seq(-3, 3, 0.5))
predict(lm(y ~ x), new, se.fit = TRUE)
pred.w.plim <- predict(lm(y ~ x), new, interval = "prediction")
pred.w.clim <- predict(lm(y ~ x), new, interval = "confidence")
matplot(new$x, cbind(pred.w.clim, pred.w.plim[,-1]),
lty = c(1,2,2,3,3), type = "l", ylab = "predicted y",
col=c(1,2,2,3,3))
points(y ~ x)
More information about the R-sig-dynamic-models
mailing list