首页 文章

使用广义线性模型来比较R中的群平均值

提问于
浏览
1

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

以前,如果我的数据不符合线性回归的假设,我就使用了数据转换 . 有时这种方法效果更好,有时也不太好 . 就我而言,我可以使用广义线性模型来比较数据的组均值 . 泊松或负二项分布,无需转换数据 .

问题是,当我拟合模型并得到模型摘要(在R中使用glm()函数)时,我没有看到完整模型的p值 - 我在模型摘要的最后一行得到的我使用lm()函数拟合线性模型 . 模型摘要 - 当使用glm()时 - 只给出每个系数的p和Z值,我可以用它们进行成对比较 .

我想获得完整模型的p值的主要思想是,我可以使用glm()代替ANOVA来处理不符合其假设的数据 .

非常感谢所有帮助!

1 回答

  • 3

    我想这就是你感兴趣的:

    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
    

相关问题