在R中使用ezANOVA输出进行计划对比

13
我一直在研究使用计划对比而不是事后t检验。我通常使用ezANOVA(Type III ANOVA),但似乎目前还不支持使用ezANOVA进行计划对比。
另一方面,aov()是一种Type I ANOVA(我不想就哪种类型适用于哪种设计展开辩论)。使用aov()进行计划对比很容易(针对分组设计),但我想在重复测量中进行Type III ANOVA,而ezANOVA的输出更加用户友好。
请注意,考虑到ezANOVA有包括return_aov = TRUE的选项,是否有人知道如何利用ezANOVA提供的信息进行计划对比? 注意:return_aov = TRUE允许通过以下方式访问aov的输出:
summary.lm(ModelName$aov$'Participant:IndependentVariable1')

上面的参与者是在ezANOVA中添加到wid的示例变量:

wid = .(Participant)

summary.lm()通常用于在计划对比结果时展示aov,而不是重复测量的组间方差分析。

我特别想使用这个输出来进行重复测量ANOVA的计划对比。

BOUNTY GOALS

我想从这个奖励中实现以下目标:

1)使用ezANOVA的输出来在重复测量ANOVA中进行计划对比。

1A)使用ezANOVA的输出来在组间ANOVA中进行计划对比(这个应该相对容易,因此不是索赔奖励的必备条件)。

任何虚拟数据都可以,但是这里有一个关于ezANOVA重复测量ANOVA格式的提醒:

ModelName <- ezANOVA(
data = DataSet,
dv = .(DependentVariable), 
wid = .(Participant), 
within = .(IndependentVariable1, IndependentVariable2), 
type=3, 
detailed = TRUE, 
return_aov = TRUE)

这是一个与此问题相关的可重现数据和代码的相关问题

您可以在此处找到PDF文件,了解有关计划对比的背景和作用。


根据软件包开发者在2012年左右发表的声明,无法使用ez进行计划对比。请参见https://groups.google.com/forum/#!topic/ez4r/RpwYT6pEva0。然而,如果您遵循此链接,将讨论可能有用的替代方案。也许查看他是否自那时以来更新了一些内容也会有所帮助... - coffeinjunky
@coffeinjunky 我怀疑作者指的是ezANOVA中缺乏直接功能,但是可能可以使用它产生的信息来使用新功能。例如,我在这里提供了一个“hack”用于ggplot 2,使用了可用功能的方式,这不是它的本意:https://dev59.com/OnE85IYBdhLWcg3wMQlm#20426482 这就是我希望这个赏金能够鼓励的。 - Docconcoct
1个回答

2
emmeans包提供了适当的功能,用于计算aovaovlist对象的估计边际均值(EMMs)的自定义对比/任意线性函数(有关支持的模型的完整列表,请参见此处)。
以下示例使用ez包中的ANT数据集。
首先,我们使用ezANOVA设置混合因子方差分析。请注意,为了获得有意义的III型检验结果,需要设置正交对比(例如,请参见John Fox在此处的回答)。
library("ez")
library("emmeans")

# set orthogonal contrasts
options(contrasts = c("contr.sum", "contr.poly"))

data(ANT)
rt_anova <- ezANOVA(data = ANT[ANT$error == 0, ], 
                    dv = rt,
                    wid = subnum, 
                    within = .(cue, flank),
                    between = group,
                    type = 3,
                    return_aov = TRUE)

我们可以计算出所有组-侧翼组合的EMMs。
emm <- emmeans(rt_anova$aov, ~ group * flank)
emm
## group     flank         emmean       SE    df lower.CL upper.CL
## Control   Neutral     381.5546 1.735392 53.97 378.0753 385.0339
## Treatment Neutral     379.9286 1.735392 53.97 376.4493 383.4079
## Control   Congruent   381.6363 1.735392 53.97 378.1570 385.1155
## Treatment Congruent   379.7520 1.735392 53.97 376.2727 383.2313
## Control   Incongruent 466.6770 1.735392 53.97 463.1977 470.1563
## Treatment Incongruent 452.2352 1.735392 53.97 448.7559 455.7145

现在,对这些EMM进行所有成对比较或任何所需的对比计算变得很容易。
如需了解如何从假设中推导出对比权重的更多详细信息,请参阅书章节和我在这里的答案。

# all pairwise comparisons 
pairs(emm, adjust = "Holm")
## contrast                                        estimate       SE    df t.ratio p.value
## Control,Neutral - Treatment,Neutral           1.62594836 2.454215 53.97   0.663  1.0000
## Control,Neutral - Control,Congruent          -0.08167403 2.473955 36.00  -0.033  1.0000
## Control,Neutral - Treatment,Congruent         1.80259257 2.454215 53.97   0.734  1.0000
## Control,Neutral - Control,Incongruent       -85.12239797 2.473955 36.00 -34.407  <.0001
## Control,Neutral - Treatment,Incongruent     -70.68062093 2.454215 53.97 -28.800  <.0001
## Treatment,Neutral - Control,Congruent        -1.70762239 2.454215 53.97  -0.696  1.0000
## Treatment,Neutral - Treatment,Congruent       0.17664421 2.473955 36.00   0.071  1.0000
## Treatment,Neutral - Control,Incongruent     -86.74834633 2.454215 53.97 -35.347  <.0001
## Treatment,Neutral - Treatment,Incongruent   -72.30656929 2.473955 36.00 -29.227  <.0001
## Control,Congruent - Treatment,Congruent       1.88426660 2.454215 53.97   0.768  1.0000
## Control,Congruent - Control,Incongruent     -85.04072394 2.473955 36.00 -34.374  <.0001
## Control,Congruent - Treatment,Incongruent   -70.59894690 2.454215 53.97 -28.766  <.0001
## Treatment,Congruent - Control,Incongruent   -86.92499054 2.454215 53.97 -35.419  <.0001
## Treatment,Congruent - Treatment,Incongruent -72.48321351 2.473955 36.00 -29.299  <.0001
## Control,Incongruent - Treatment,Incongruent  14.44177704 2.454215 53.97   5.884  <.0001
## 
## Results are averaged over the levels of: cue 
## P value adjustment: holm method for 15 tests 

# custom contrasts
contrast(
  emm, 
  list(c1 = c(1, -1, 0, 0, 0, 0), # reproduces first pairwise comparison
       # emmean of row 1 - (emmean of row 1 + emmean of row 2) / 2; see EMMs table
       # 381.5546 - (379.9286 + 381.6363) / 2
       c2 = c(1, -0.5, -0.5, 0, 0, 0))
 )
 ## contrast  estimate       SE    df t.ratio p.value
 ## c1       1.6259484 2.454215 53.97   0.663  0.5105
 ## c2       0.7721372 2.136825 43.84   0.361  0.7196

对于纯粹的受试者内部方差分析或受试者间方差分析也是适用的。

# within-subjects ANOVA
rt_anova_wi <- ezANOVA(data = ANT[ANT$error == 0, ], 
                    dv = rt,
                    wid = subnum, 
                    within = .(cue, flank),
                    type = 3,
                    return_aov = TRUE)

emm <- emmeans(rt_anova_wi$aov, ~ cue * flank)
contrast(
  emm, 
  list(c1 = c(1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), 
       c2 = c(1, -0.5, -0.5, 0, 0, 0, 0, 0, 0, 0, 0, 0))
) 
## contrast estimate       SE     df t.ratio p.value
## c1       47.31005 3.802857 170.34  12.441  <.0001
## c2       50.35320 3.293371 170.34  15.289  <.0001

# between-subjects ANOVA
rt_anova_bw <- ezANOVA(data = ANT[ANT$error == 0, ], 
                       dv = rt,
                       wid = subnum, 
                       within_full = .(cue, flank), 
                       between = group,
                       type = 3,
                       return_aov = TRUE)

emm_bw <- emmeans(rt_anova_bw$aov, ~ group)
# custom linear function
contrast(
  emm_bw, 
  list(c1 = c(2/3, 1/2)) 
)
## contrast estimate        SE df t.ratio p.value
## c1       475.2899 0.8213448 18 578.673  <.0001

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接