Calculate confidence intervals for pairwise comparison using lsmeans/emmeans in R

1.6k views Asked by At

I am using the lsmeans/emmeans package in R to create a plot of pairwise comparisons in the response between levels of treatA (binary/factor variable). I can get the difference estimates using lsmeans (contrast), but it only provides the SE for the estimates, not the confidence limits. Confidence limits are only provided for the individual effects, not the contrasts. Can anyone help generate CL for the mean differences (contrasts)?

model = glmer.nb(response ~ treatA * treatB + (1|random), data, family=nbinom1)

lsm <- lsmeans(model, pairwise ~ treatA*treatB)

contrast(lsm, method = "pairwise")

I am ultimately hoping to make a plot like this, but with CL instead of SE.

enter image description here

1

There are 1 answers

0
Russ Lenth On
confint(lsm[[2]])

plot(lsm[[2]], CIs = TRUE)

Look at the documentation for more details