使用广义线性模型比较 R 中的组均值

Using generalized linear models to compare group means in R

我经常使用线性回归来测试各组之间的平均值是否不同,方法是对我的分类变量进行虚拟编码,我认为这与使用方差分析基本相同(或者至少我得到相同的结果)。我在 R 中使用 lm() 函数来执行此操作。

以前,如果我的数据不符合线性回归的假设,我会使用数据转换。有时这效果更好,有时效果不佳。就我而言,我可以使用广义线性模型来比较以下数据的组均值,例如不需要转换数据的泊松分布或负二项分布。

问题是,当我拟合模型并获取模型摘要(使用 R 中的 glm() 函数)时,我没有看到完整模型的 p 值——这是我在最后一行中得到的当我使用 lm() 函数拟合线性模型时的模型摘要。模型摘要 - 使用 glm() 时 - 仅给出每个系数的 p 和 Z 值,我可以将其用于成对比较。

我想获得完整模型的 p 值的主要想法是,对于不符合其假设的数据,我可以使用 glm() 代替方差分析。

非常感谢所有帮助!

我想这是你感兴趣的:

counts <- c(18,17,15,20,10,20,25,13,12)
outcome <- gl(3,1,9)
treatment <- gl(3,3)

# fit the model of interest
glm.D93 <- glm(counts ~ outcome + treatment, family = poisson())

# fit the a NULL model
glm.NULL <- glm(counts ~ 1, family = poisson())

# compare the model of interest to the null model
anova(glm.D93,glm.NULL,test = "F")

您可以看到同样的事情适用于线性模型:

# fit the model of interest
lm.D93 <- lm(counts ~ outcome + treatment)

# fit the a NULL model
lm.NULL <- lm(counts ~ 1)

anova(lm.D93,lm.NULL,test = "F")
#> Analysis of Variance Table
#> ...
#>   Res.Df     RSS Df Sum of Sq     F  Pr(>F)
#> 1      4  83.333  
#> 2      8 176.000 -4   -92.667 1.112  0.4603

summary(lm.D93)

#> Residual standard error: 4.564 on 4 degrees of freedom
#> Multiple R-squared:  0.5265,    Adjusted R-squared:  0.05303 
#> F-statistic: 1.112 on 4 and 4 DF,  p-value: 0.4603