gpt4 book ai didi

r - glm 模型的一个 p 值

转载 作者:行者123 更新时间:2023-12-04 11:39:39 25 4
gpt4 key购买 nike

我正在寻找一种方法来获得一个 p 值,该值描述了 glm 模型的拟合优度。这是 lm 联机帮助页中的一个稍微修改过的示例:

 ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
conf<- c(rnorm(mean=-1, sd=1, n=10), rnorm(mean=1, sd=1, n=10))

group <- gl(2,10,20, labels=c("Ctl","Trt"))
weight <- c(ctl, trt)
lm.D9 <- lm(weight ~ group + conf)

通过 summary(lm.D9) 得到

Call:
lm(formula = weight ~ group + conf)

Residuals:
Min 1Q Median 3Q Max
-1.17619 -0.40373 -0.05262 0.24987 1.40777

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 4.97416 0.25153 19.775 3.6e-13 ***
groupTrt -0.23724 0.41117 -0.577 0.572
conf -0.07044 0.13725 -0.513 0.614
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.7111 on 17 degrees of freedom
Multiple R-squared: 0.08722, Adjusted R-squared: -0.02017
F-statistic: 0.8122 on 2 and 17 DF, p-value: 0.4604

如果 id 对 glm 做同样的事情

glm.D9 <- glm(weight ~ group + conf)
summary(glm.D9)

我明白了

Call:
glm(formula = weight ~ group + conf)

Deviance Residuals:
Min 1Q Median 3Q Max
-1.17619 -0.40373 -0.05262 0.24987 1.40777

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 4.97416 0.25153 19.775 3.6e-13 ***
groupTrt -0.23724 0.41117 -0.577 0.572
conf -0.07044 0.13725 -0.513 0.614
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(Dispersion parameter for gaussian family taken to be 0.5056514)

Null deviance: 9.4175 on 19 degrees of freedom
Residual deviance: 8.5961 on 17 degrees of freedom
AIC: 47.869

Number of Fisher Scoring iterations: 2

lm 具有 F 统计量作为整个模型的摘要,glm 没有。那么问题又来了:我怎样才能从描述拟合的 glm 模型中得到一个 p 值?

谢谢

最佳答案

您可以像这样计算 F 统计量:

glm.D9 <- glm(weight ~ group + conf)

glm.0 <- glm(weight ~ 1)

anova(glm.D9, glm.0, test="F")

# Analysis of Deviance Table
#
# Model 1: weight ~ group + conf
# Model 2: weight ~ 1
# Resid. Df Resid. Dev Df Deviance F Pr(>F)
# 1 17 8.5868
# 2 19 9.4175 -2 -0.8307 0.8223 0.4562

有关详细信息和其他可用测试,请参阅 ?anova.glm

关于r - glm 模型的一个 p 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17674148/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com