简体   繁体   English

如何使用 R 中的正确(在受试者内)错误项对双向混合方差分析中的显着交互进行事后测试?

[英]How can I run post-hoc tests for a significant interaction in Two-Way Mixed ANOVA with the correct (within subjects) error term in R?

I am attempting run a Fisher's LSD post hoc test on a Two-Way Mixed Model ANOVA using the "afex" and "emmeans" packages.我正在尝试使用“afex”和“emmeans”包在双向混合模型方差分析上运行 Fisher 的 LSD 事后测试。 The data I am using has one between-subjects factor "group" which has 2 levels, and one within-subjects factor "time" which has 3 levels (ie its a 2 x 3 design).我使用的数据有一个具有 2 个级别的主体间因子“组”和一个具有 3 个级别的主体内因子“时间”(即它的 2 x 3 设计)。 The DV is "score". DV是“分数”。 Here is some model data that I created to replicate the error:这是我为复制错误而创建的一些模型数据:

library(tidyverse)
library(dplyr)
library(afex)
library(emmeans)
# Create data
set.seed(35)
df1 <- data.frame(id = factor(rep(1:12, each = 3)),
                  time = factor(rep(c(1:3), 12)),
                  group = factor(rep(1:2, each = 18)),
                  score = rnorm(36, 20, 5))

...And here is how I am constructing the ANOVA model: ...这是我构建方差分析模型的方式:

# Run Two-way Mixed Model ANOVA
model1 <- aov_car(score ~ time*group +
                            Error(id/time), 
                          data = df1)

The output F-table for this two-way ANOVA looks like this, though, when I run it on my actual data there is a significant interaction effect:这个双向方差分析的输出 F 表看起来像这样,但是,当我在我的实际数据上运行它时,会产生显着的交互效应:

Anova Table (Type 3 tests)

Response: score
      Effect          df   MSE      F  ges p.value
1      group       1, 10 27.50 4.11 + .130    .070
2       time 1.72, 17.19 28.02   0.50 .031    .589
3 group:time 1.72, 17.19 28.02   1.09 .065    .350
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘+’ 0.1 ‘ ’ 1

Because there is a significant interaction in my actual data, I would like to conduct follow-up tests.因为在我的实际数据中有显着的交互作用,所以我想进行后续测试。 Specifically, I would like to look at the effect of time for each group separately (in a within-subjects manner).具体来说,我想分别看看时间对每个组的影响(以受试者内的方式)。 I tried to run both a simple main effects test and multiple comparisons(Fisher's LSD) using this code:我尝试使用以下代码运行简单的主效应测试和多重比较(Fisher's LSD):

# Run whithin-subject simple main effect  
simple.effect <-emmeans(model1, ~time|group, model = 
                "multivariate")
test(pairs(simple.effect), joint=TRUE)

# Run Fisher's LSD multiple comparison 
pairs(simple.effect, adjust='none')

Which returns this:这会返回:

> # Run whithin-subject simple main effect  
> simple.effect <-emmeans(model1, ~time|group, model = "multivariate")
> test(pairs(simple.effect), joint=TRUE)
 group df1 df2 F.ratio p.value note
 1       2  10   1.009  0.3989  d  
 2       2  10   0.374  0.6969  d  

d: df1 reduced due to linear dependence 
> # Run Fisher's LSD multiple comparison 
> pairs(simple.effect, adjust='none')
group = 1:
 contrast estimate   SE df t.ratio p.value
 X1 - X2    -3.792 2.74 10  -1.386  0.1959
 X1 - X3     0.231 2.35 10   0.098  0.9236
 X2 - X3     4.023 3.33 10   1.209  0.2544

group = 2:
 contrast estimate   SE df t.ratio p.value
 X1 - X2    -0.199 2.74 10  -0.073  0.9435
 X1 - X3    -2.030 2.35 10  -0.863  0.4082
 X2 - X3    -1.831 3.33 10  -0.550  0.5942

For both of these sets of tests the df error reads 10 (which is the error associated with "group" - the between-subjects factor).对于这两组测试,df 错误读数为 10(这是与“组”相关的错误 - 受试者之间的因素)。 I believe that the df error should actually be 17.19 (which would correspond to the error term for the within-subjects factor ("time").我相信 df 错误实际上应该是 17.19 (这将对应于主体内因子(“时间”)的错误项。

It seems to me as though "emmeans" is using the wrong df/MS error to run the follow-up tests, but I don't know how to tell it to use the right one.在我看来,“emmeans”似乎使用了错误的 df/MS 错误来运行后续测试,但我不知道如何告诉它使用正确的错误。 Any help would be greatly appreciated.任何帮助将不胜感激。

This is what I get:这就是我得到的:

> simple.effect <- emmeans(model1, ~time|group, model = "univariate")
aov object missing, substituting multivariate/lm model.
to get univariate tests, refit ANOVA with include_aov = TRUE

Note from the message that asking for the univariate model did not produce it.请注意,请求单变量模型并没有产生它。 Doing what is recommended in the message, I re-fitted the model:按照消息中的建议,我重新安装了模型:

> model2 <- aov_car(score ~ time*group +
+                       Error(id/time), include_aov = TRUE, 
+                   data = df1)
Contrasts set to contr.sum for the following variables: group

> simple.effect2 <- emmeans(model2, ~time|group, model = "univariate")
> pairs(simple.effect2)
group = 1:
 contrast estimate   SE df t.ratio p.value
 X1 - X2    -3.792 2.83 20  -1.338  0.3912
 X1 - X3     0.231 2.83 20   0.082  0.9963
 X2 - X3     4.023 2.83 20   1.420  0.3499

group = 2:
 contrast estimate   SE df t.ratio p.value
 X1 - X2    -0.199 2.83 20  -0.070  0.9973
 X1 - X3    -2.030 2.83 20  -0.716  0.7568
 X2 - X3    -1.831 2.83 20  -0.646  0.7966

P value adjustment: tukey method for comparing a family of 3 estimates

The pairwise differences each show 20 df Also (not shown), the means themselves have 29.9 df (Note that you have to specify the univariate model because it still defaults to the multivariate one).成对差异均显示 20 df 此外(未显示),均值本身具有 29.9 df(请注意,您必须指定单变量模型,因为它仍默认为多变量模型)。

By the way, I don't think most users would deem an interaction "significant" when it has a P value of 0.35.顺便说一句,当 P 值为 0.35 时,我认为大多数用户不会认为交互“显着”。 They would just obtain the EMMs for time without conditioning on group .他们只会在time上获得 EMM,而不以group为条件。 The df remain at 10 with the multivariate model and at 20 with the univariate model.多变量模型的 df 保持在 10,单变量模型的 df 保持在 20。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM