我知道可以用AICcmodavg获得预测值(原始尺度〜概率)和SE的固定效果,但是我没有成功地尝试...有人可以帮助我吗?提前致谢
library(lme4)
(gm1 <- glmer(cbind(incidence, size - incidence) ~ period + (1 | herd),
data = cbpp, family = binomial))
fixef(gm1)
library("AICcmodavg")
predictSE(gm1,
newdata=as.data.frame(period=c("period1","period2","period3","period4")),
type="response",
se.fit=TRUE,
level=0,
print.matrix=F)
答案 0 :(得分:2)
最好是阅读levels(cbpp$period)
,而不是as.data.frame()
,而是data.frame()
levels(cbpp$period)
# [1] "1" "2" "3" "4"
predictSE(gm1,
newdata = data.frame(period=c("1", "2", "3", "4")),
type = "response",
se.fit = TRUE,
level = 0,
print.matrix = F)
的 [编辑] 强>
fit <- ...(..., data = df)
predictSE(fit, newdata = df)
predictSE(fit, newdata = ...)
# If 1st predictSE() doesn't run, it means the model causes error.
# If 1st runs but 2nd doesn't, it means it is due to newdata.
如果你的模型有两个因素;
newd <- expand.grid(name1 = levels(df$name1), name2 = levels(df$name2))
predictSE(fit, newdata = newd)
# pred <- predictSE(fit, newdata = newd)
# cbind(newd, pred) # help to interpret