2
$\begingroup$

I am using lmer in R to check the effect of treatment and a group on some result (y). In my data (dat), there are 3 categorical variables and a continuous response variable: 1 id 1 treatment variable with 3 categories: ctrl, treat1, treat2 1 group variable with categories a, b, c And a continuous variable y.

I fit a lmer model:

library(lmer) library(emmeans)

Mod=lmer(y ~ Treatment*group +(1 | id), data=dat).

At first, i want to compare the change from control for the treat1, and treat2. (treat1 vs ctrl, treat2 vs ctrl). I know how to do this using trt.vs.ctrl contrasts in the emmeans package.

emmeans(Mod, trt.vs.ctrl~treat, data=dat)

At second, for each treatment (treat1 and treat2) i want to compare the change from control between the groups a and b, b and c, a and c.

For this latter, i want to set the contrasts in R with the emmeans package but don't know how to do it.

I would be grateful to anyone who will help me to find a way to solve this question. Thanks you in advance

$\endgroup$

1 Answer 1

1
$\begingroup$

To keep things straight, I suggest doing the contrasts and EMMs in separate steps.

emm <- emmeans(Mod, ~ Treatment * group)
con <- contrast(emm, "trt.vs.ctrl", by = "group")
con   # show the contrasts for each group
contrast(con, "pairwise", by = "contrast")

You can do the contrasts in one step, but it's a little more confusing:

contrast(emm, interaction = c("trt.vs.ctrl", "pairwise"))

For more information and examples, see vignette("interactions", "emmeans")

$\endgroup$
1
  • $\begingroup$ Thank you a lot! Your answer helped me a lot $\endgroup$
    – FalleS
    Commented Jan 14, 2021 at 23:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.