如前所述,您的问题已由@francium87d 回答。将残差与适当的卡方分布进行比较构成了对饱和模型的拟合模型测试,并在这种情况下显示出显着缺乏拟合。
尽管如此,更彻底地查看数据和模型可能有助于更好地理解模型缺乏拟合意味着什么:
d = read.table(text=" age education wantsMore notUsing using
<25 low yes 53 6
<25 low no 10 4
<25 high yes 212 52
<25 high no 50 10
25-29 low yes 60 14
25-29 low no 19 10
25-29 high yes 155 54
25-29 high no 65 27
30-39 low yes 112 33
30-39 low no 77 80
30-39 high yes 118 46
30-39 high no 68 78
40-49 low yes 35 6
40-49 low no 46 48
40-49 high yes 8 8
40-49 high no 12 31", header=TRUE, stringsAsFactors=FALSE)
d = d[order(d[,3],d[,2]), c(3,2,1,5,4)]
library(binom)
d$proportion = with(d, using/(using+notUsing))
d$sum = with(d, using+notUsing)
bCI = binom.confint(x=d$using, n=d$sum, methods="exact")
m = glm(cbind(using,notUsing)~age+education+wantsMore, d, family=binomial)
preds = predict(m, new.data=d[,1:3], type="response")
windows()
par(mar=c(5, 8, 4, 2))
bp = barplot(d$proportion, horiz=T, xlim=c(0,1), xlab="proportion",
main="Birth control usage")
box()
axis(side=2, at=bp, labels=paste(d[,1], d[,2], d[,3]), las=1)
arrows(y0=bp, x0=bCI[,5], x1=bCI[,6], code=3, angle=90, length=.05)
points(x=preds, y=bp, pch=15, col="red")

该图绘制了在使用避孕措施的每组类别中观察到的女性比例,以及确切的 95% 置信区间。模型的预测比例以红色覆盖。我们可以看到两个预测的比例在 95% CI 之外,另外五个处于或非常接近各自 CI 的限制。这是 16 个 ( ) 中的 7 个偏离目标。所以模型的预测与观察到的数据不太匹配。 44%
该模型如何更好地拟合?也许相关的变量之间存在相互作用。让我们添加所有双向交互并评估拟合:
m2 = glm(cbind(using,notUsing)~(age+education+wantsMore)^2, d, family=binomial)
summary(m2)
# ...
# Null deviance: 165.7724 on 15 degrees of freedom
# Residual deviance: 2.4415 on 3 degrees of freedom
# AIC: 99.949
#
# Number of Fisher Scoring iterations: 4
1-pchisq(2.4415, df=3) # [1] 0.4859562
drop1(m2, test="LRT")
# Single term deletions
#
# Model:
# cbind(using, notUsing) ~ (age + education + wantsMore)^2
# Df Deviance AIC LRT Pr(>Chi)
# <none> 2.4415 99.949
# age:education 3 10.8240 102.332 8.3826 0.03873 *
# age:wantsMore 3 13.7639 105.272 11.3224 0.01010 *
# education:wantsMore 1 5.7983 101.306 3.3568 0.06693 .
此模型的失拟检验的 p 值现在为。但是我们真的需要所有这些额外的交互项吗?该命令显示没有它们的嵌套模型测试的结果。和之间的交互作用不是很显着,但无论如何我都可以在模型中使用它。那么让我们看看这个模型的预测与数据相比如何: 0.486drop1()educationwantsMore

这些并不完美,但我们不应该假设观察到的比例是真实数据生成过程的完美反映。这些在我看来就像它们在适当的数量上反弹(更准确地说,数据在预测周围反弹,我想)。