如何使用 emmeans 仅测试 select 成对比较?

How to only test select pairwise comparisons using emmeans?

我已经看到几个示例如何可以 select 所需的成对比较,但不幸的是不知道如何将其应用于我的数据。

这是我的缩写数据集: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' )

您需要手动提供对比度系数。在这种情况下,获取所有这些,然后删除不需要的是相当简单的;像这样:

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")