antares
antares

Reputation: 35

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

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

Upvotes: 1

Views: 1744

Answers (1)

Russ Lenth
Russ Lenth

Reputation: 6780

confint(lsm[[2]])

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

Look at the documentation for more details

Upvotes: 2

Related Questions