Reputation: 11
This is just a general question on getting confidence intervals for interactions in emmeans, I have read all the common tutorials, but I can't understand how to do it for 2-way and 3-way interactions. Heres an example for a 3-way interaction.
X= continous variable
A= 3 levels, nested in L
L= 2 levels
G= 2 levels, crossed with L (and thus also A)
ID= participants nested in G
I then fitted a linear mixed model with random intercept:
fit1 <- lmer(X~G*A*L+(1|ID),data=df)
emms=emmeans(fit1,specs=pairwise~A*L*G)
The comparisons I want is perfectly shown using:
contrast(emms,interaction="pairwise")$emmeans
However, they are missing confidence intervals, and please note that running:
summary(contrast(emms,interaction="pairwise")$emmeans,infere=T) or
confint(contrast(emms,interaction="pairwise")$emmeans)
on the emmeans data don't work, it just gives the emmeans at different levels with confidence intervals, not for the contrasts. These functions work on the contrasts data, but these do not show the 3-way interactions.
UPDATE: THE ANSWER I finally figured it out:
confint(contrast(emmeans(fit1,~A*G*L),interaction=c("pairwise")))
Upvotes: 0
Views: 959
Reputation: 6810
The interaction contrasts produced by the other answer may be what you want, but those comprise contrasts of contrasts of contrasts in a 3-way model. When interactions are present, often what people want are simple comparisons - comparisons of one factor while the others are held fixed. Those are obtainable via
pairs(emms[[1]], simple = “each”)
Upvotes: 0