The predict() function can be used to produce confidence intervals and prediction intervals for the prediction of medv for a given value of lstat. For instance, the 95% confidence interval associated with a lstat value of 10 is (24.47, 25.63), and the 95% prediction interval is (12.828, 37.28).

> predict(lm.fit, data.frame(lstat = (c(5, 10, 15))), interval = "confidence")
    fit     lwr     upr
1 29.80   29.01   30.60
2 25.05   24.47   25.63
3 20.30   19.73   20.87
> predict(lm.fit, data.frame(lstat = (c(5, 10, 15))), interval = "prediction")
    fit     lwr     upr
1 29.80  17.566   42.04
2 25.05  12.828   37.28
3 20.30   8.078   32.53

As expected, the confidence and prediction intervals are centered around the same point (a predicted value of 25.05 for medv when lstat equals 10), but the latter are substantially wider.

Try making a prediction for the model lm.fit with a 95% confidence interval for values of lstat of 6, 8 and 12:


Assume that: