简短回答:还没有完整的答案,但您可能对与链接问题相关的以下分布感兴趣:它比较 z-test(glm 也使用)和 t-test
layout(matrix(1:2,1,byrow=TRUE))
# trying all 100 possible outcomes if the true value is p=0.7
px <- dbinom(0:100,100,0.7)
p_model = rep(0,101)
p_model2 = rep(0,101)
for (i in 0:100) {
xi = c(rep(1,i),rep(0,100-i))
model = glm(xi ~ 1, offset=rep(qlogis(0.7),100), family="binomial")
p_model[i+1] = 1-summary(model)$coefficients[4]
model2 <- glm(xi ~ 1, family = "binomial")
coef <- summary(model2)$coefficients
p_model2[i+1] = 1-2*pt(-abs((qlogis(0.7)-coef[1])/coef[2]),99,ncp=0)
}
# plotting cumulative distribution of outcomes z-test
outcomes <- p_model[order(p_model)]
cdf <- cumsum(px[order(p_model)])
plot(1-outcomes,1-cdf,
ylab="cumulative probability",
xlab= "calculated glm p-value",
xlim=c(10^-4,1),ylim=c(10^-4,1),col=2,cex=0.5,log="xy")
lines(c(0.00001,1),c(0.00001,1))
for (i in 1:100) {
lines(1-c(outcomes[i],outcomes[i+1]),1-c(cdf[i+1],cdf[i+1]),col=2)
# lines(1-c(outcomes[i],outcomes[i]),1-c(cdf[i],cdf[i+1]),col=2)
}
title("probability for rejection with z-test \n as function of set alpha level")
# plotting cumulative distribution of outcomes t-test
outcomes <- p_model2[order(p_model2)]
cdf <- cumsum(px[order(p_model2)])
plot(1-outcomes,1-cdf,
ylab="cumulative probability",
xlab= "calculated glm p-value",
xlim=c(10^-4,1),ylim=c(10^-4,1),col=2,cex=0.5,log="xy")
lines(c(0.00001,1),c(0.00001,1))
for (i in 1:100) {
lines(1-c(outcomes[i],outcomes[i+1]),1-c(cdf[i+1],cdf[i+1]),col=2)
# lines(1-c(outcomes[i],outcomes[i]),1-c(cdf[i],cdf[i+1]),col=2)
}
title("probability for rejection with t-test \n as function of set alpha level")
[![p-test vs t-test][1]][1]
而且只有很小的区别。而且 z 检验实际上更好(但这可能是因为 t 检验和 z 检验都是“错误的”,并且 z 检验的误差可能补偿了这个误差)。
长答案: ...