# [R] plot out the predicted values and the upper and lower limits

MacQueen, Don macqueen1 at llnl.gov
Wed Feb 26 23:54:18 CET 2014

```When in doubt, first consult the included online help.

?predict.lm

Offers this example, which seems to meet the request

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")

(note that all the functions come with R and are loaded by default)

And predict.lm can be found in the "See also" section of ?predict.

-Don

--
Don MacQueen

Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062

On 2/25/14 2:57 PM, "varin sacha" <varinsacha at yahoo.fr> wrote:

>Hi,
>I have realized a multiple linear regression.
>To know how well my model does in terms of prediction, I can compute
>prediction intervals bands and decide if they are narrow enough to be of
>use. If they are too wide, then they probably are not useful.
>
>So what I am trying to do is :
>Theoretically I know that I can use the "predict" command in R to
>generate the prediction interval for a set of points. The idea is to find
>the linear regression using the lm command. Then I can use the predict
>command to get the prediction interval for a set of points in the domain.
>Then I plot out the predicted values as well as the upper and lower
>limits of the prediction intervals for those values.
>My problem is to practice what I theoretically know, especially using R.
>
>My linear model is the following :
>LinearModel.1 <- lm(GDP.per.head ~ Competitivness.score + Quality.score,
>data=Dataset)
>summary(LinearModel.1)
>predict(LinearModel.1, se.fit = FALSE, scale = NULL, df = Inf,interval =
>c("none", "confidence", "prediction"),level = 0.95, type = c("response",
>"terms"),terms = NULL)
>
>Could you please help me with my R codes ?
>
>Thanks for your precious help,
>	[[alternative HTML version deleted]]
>

```

More information about the R-help mailing list