使用'stats'中的预测函数的置信区间

问题描述 投票:0回答:1

我试图在R中显示单个预测的95%置信区间。通常使用的modavgPred函数会给我关于模型类的错误,所以我假设这是因为我正在运行它放在glm而不是glmer上。所以我在predict包中使用了stats函数,使用此代码

predictions<-predict(vel.occ.2, newdata=newdatvel, type="response", se.fit=TRUE, interval = "prediction")

http://www.sthda.com/english/articles/40-regression-analysis/166-predict-in-r-model-predictions-and-confidence-intervals/建议使用interval="prediction"参数,但是当我将其添加到代码行时,它不会将配置项添加到我的输出中。

有人对线性模型的置信区间预测有其他建议吗?

r glm confidence-interval
1个回答
0
投票
model2 <- glm(hon~write, honors, family = "binomial")
summary(model2)

pred <- predict(model2,newdata = hon[,-4], type = "link", se.fit = TRUE)

fitted <- pred$fit
alpha <- 1.96 ## approx 95% CI
upper <- pred$fit + (alpha * pred$se.fit)
lower <- pred$fit - (alpha * pred$se.fit)
© www.soinside.com 2019 - 2024. All rights reserved.