如何使用emmeans仅测试选择的成对比较?

3

我看到了几个例子,它们可能会选择所需的成对比较,但是不幸的是,我不知道如何将其应用于我的数据。

这是我的缩写数据集:https://www.dropbox.com/s/x9xjc9o0222rg0w/df.csv?dl=0


# FIXED effects: age and brain_area

df$age <- factor(df$age)
df$brain_area <- factor(df$brain_area)

# RANDOM effects: subject_ID and section

df$subject_ID <- factor(df$subject_ID)
df$section <- factor(df$section)

# dependent variable: DV

# ___________________ mixed TWO-way ANOVA 
require(lme4)
require(lmerTest)
require(emmeans)

model = lmer(DV ~ age * brain_area + (1 | subject_ID), data = df)  

anova(model) #  significant interaction and both main effects

# ____________________ ALL pairwise comparisons

emmeans(model, pairwise~brain_area|age, adj='fdr')

# ____________________ I marked below comparisons that I would like to exclude (but keep all others)

$contrasts
age = old:
  contrast    estimate     SE  df t.ratio p.value
a - b         0.0412 0.0158 174   2.603  0.0125
a - c        -0.0566 0.0158 174  -3.572  0.0007
a - control   0.3758 0.0158 174  23.736  <.0001    # exclude
a - d        -0.0187 0.0158 174  -1.182  0.2387
b - c        -0.0978 0.0158 174  -6.175  <.0001
b - control   0.3346 0.0158 174  21.132  <.0001    # exclude
b - d        -0.0599 0.0158 174  -3.786  0.0004
c - control   0.4324 0.0158 174  27.308  <.0001
c - d         0.0378 0.0158 174   2.389  0.0199
control - d  -0.3946 0.0158 174 -24.918  <.0001    # exclude

age = young:
  contrast    estimate     SE  df t.ratio p.value
a - b         0.0449 0.0147 174   3.063  0.0032
a - c        -0.0455 0.0147 174  -3.105  0.0032
a - control   0.2594 0.0147 174  17.694  <.0001    # exclude
a - d         0.0202 0.0147 174   1.377  0.1702
b - c        -0.0904 0.0147 174  -6.169  <.0001
b - control   0.2145 0.0147 174  14.631  <.0001    # exclude
b - d        -0.0247 0.0147 174  -1.686  0.1040
c - control   0.3049 0.0147 174  20.799  <.0001
c - d         0.0657 0.0147 174   4.483  <.0001
control - d  -0.2392 0.0147 174 -16.317  <.0001    # exclude

# ____________________ The line below seems to work BUT completely excludes 'control' level from factor 'brain_area'. I do not wish to completely exclude it...

emmeans(model, specs=pairwise~brain_area| age,
               at = list(brain_area = c("a", "b", "c", "d")), adj='fdr' )

1
请参见 glht::multcomp ... - Ben Bolker
非常感谢您的建议!但是我恐怕无法弄清楚如何使它工作 :( - user7395965
@BenBolker,我不明白将其移动到glht如何解决排除某些对比的特定问题。 - Russ Lenth
1个回答

4

您需要手动提供对比系数。在这种情况下,很容易获取所有系数,然后删除您不想要的系数;类似以下方法:

EMM <- emmeans(model, ~ brain_area | age)
EMM     # show the means

coef <- emmeans:::pairwise.emmc(levels(EMM)[["brain_area"]])
coef <- coef[-c(3, 6, 10)]

contrast(EMM, coef, adjust = "fdr")

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