In R predict.lm computes predictions based on the results from linear regression and also offers to compute confidence intervals for these predictions. According to the manual, these intervals are based on the error variance of fitting, but not on the error intervals of the coefficient.
On the other hand predict.glm which computes predictions based on logistic and Poisson regression (amongst a few others) doesn’t have an option for confidence intervals. And I even have a hard time imagining how such confidence intervals could be computed to provide a meaningful insight for Poisson and logistic regression.
Are there cases in which it is meaningful to provide confidence intervals for such predictions? How can they be interpreted? And what are the assumptions in these cases?
The usual way is to compute a confidence interval on the scale of the linear predictor, where things will be more normal (Gaussian) and then apply the inverse of the link function to map the confidence interval from the linear predictor scale to the response scale.
To do this you need two things;
predict()withtype = "link", andpredict()withse.fit = TRUE.The first produces predictions on the scale of the linear predictor, the second returns the standard errors of the predictions. In pseudo code
predsis then a list with componentsfitandse.fit.The confidence interval on the linear predictor is then
critvalis chosen from a t or z (normal) distribution as required (I forget exactly now which to use for which type of GLM and what the properties are) with the coverage required. The1.96is the value of the Gaussian distribution giving 95% coverage:Now for
fit,uprandlwrwe need to apply the inverse of the link function to them.Now you can plot all three and the data.