6
$\begingroup$

I have a model and a graph:

n1 = glm(formula = cbind(ml, ad) ~ x1, family = "quasibinomial")
plot(x1, ml/(ml+ad))

And I would like to plot a predicted line with a confidence interval. I would like to write this (as in predict.lm):

predict_n1s <- predict.glm(n1, data.frame(x1 = seq(..)), type = "response", 
                           interval = c("confidence"))

But the interval option doesn't work for predict.glm! Is there any possibility how to call this?

If there is not, is this workaround OK?

n1_x <- seq(par("usr")[1], par("usr")[2], length.out = 200)
predict <- predict.glm(n1, data.frame(x1 = n1_x), type = "link", se.fit = TRUE)
lines(x = n1_x, y = n1$family$linkinv(predict$fit), col = "red")
lines(x = n1_x, y = n1$family$linkinv(predict$fit + predict$se.fit * 1.96), col = "red", lty = 2)
lines(x = n1_x, y = n1$family$linkinv(predict$fit - predict$se.fit * 1.96), col = "red", lty = 2)
$\endgroup$
  • 5
    $\begingroup$ Your workaround appears to be Wald-based confidence intervals, not prediction intervals. See mail 1 and mail 2 on the R-help list. $\endgroup$ – caracal Oct 26 '12 at 18:43
  • $\begingroup$ I think we should use the binomial distribution instead of the normal one. $\endgroup$ – skan Oct 26 '15 at 11:06
  • $\begingroup$ There are still CIs based on the coefficients alone. For a prediction interval, you'd need to do something with a quantile function. $\endgroup$ – jebyrnes Jan 26 '17 at 16:04