我有一个模型和一个图表:
n1 = glm(formula = cbind(ml, ad) ~ x1, family = "quasibinomial")
plot(x1, ml/(ml+ad))
我想绘制一条带有置信区间的预测线。我想写这个(如predict.lm):
predict_n1s <- predict.glm(n1, data.frame(x1 = seq(..)), type = "response",
interval = c("confidence"))
但该interval
选项不适用于predict.glm
!有没有可能怎么称呼这个?
如果没有,这种解决方法可以吗?
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)