Prediction Interval for Linear Regression
Assume that the error term ϵ in the simple linear regression model is independent of x, and is normally distributed, with zero mean and constant variance. For a given value of x, the interval estimate of the dependent variable y is called the prediction interval.
In the data set faithful, develop a 95% prediction interval of the eruption duration for the waiting time of 80 minutes.
We apply the lm function to a formula that describes the variable eruptions by the variable waiting, and save the linear regression model in a new variable eruption.lm.
Then we create a new data frame that set the waiting time value.
We now apply the predict function and set the predictor variable in the newdata argument. We also set the interval type as "predict", and use the default 0.95 confidence level.
fit lwr upr
1 4.1762 3.1961 5.1564
> detach(faithful) # clean up
The 95% prediction interval of the eruption duration for the waiting time of 80 minutes is between 3.1961 and 5.1564 minutes.
Further detail of the predict function for linear regression model can be found in the R documentation.