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

Rolf Turner r.turner at auckland.ac.nz
Wed Feb 26 02:22:36 CET 2014


On 26/02/14 11:57, varin sacha 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 ?

If you want prediction intervals, ask for them!!!  There is no point at 
all in simply repeating the default for the argument "interval".  If you 
actually want the default, then don't say anything at all.  I.e. omit 
the "interval" argument from your call and don't clutter things up with 
irrelevancies.

But here you *don't* want the default (which is "none").  You want
"prediction".  So set interval="prediction" in your call.  Actually you 
can just set interval="p" because of partial argument matching.

cheers,

Rolf Turner




More information about the R-help mailing list