I'm running mixed effects models in R using Treatment and Species as crossed predictors and Group as a random effect using the nlme package, like so:
model <- lme(growth_rate ~ Treatment * Species, random = ~1|Group, data = data, method="REML")
I wanted to run a post-hoc test to perform pairwise comparisons, i.e. compare how different treatment/species combinations compare to each other.
I was having some trouble getting the emmeans package to run (though I have solved this issue now). Someone suggested an alternative to emmeans, which was to construct 95% confidence intervals for my predicted values (as described here). I was told that treatment/species combinations with confidence intervals that do not overlap could be considered to be significantly different. Is this correct and if so, why don't we need to correct for multiple comparisons?
Here is how I manually computed the confidence intervals from the model based on the code from the link:
newdat <- expand.grid(Treatment=c("A", "B", "C", "C", "E"), Species=c("X", "Y"))
newdat$pred <- predict(model, newdat, level = 0)
## [-2] drops response from formula
Designmat <- model.matrix(formula(model)[-2], newdat)
##compute XVX' to get variance-covariance matrix of predictions and extract the diagonal to get variances of predictions
predvar <- diag(Designmat %*% vcov(model) %*% t(Designmat))
##take square root of variances to get the standard deviations (errors) of the predictions
newdat$SE <- sqrt(predvar)
cmult <- 1.96
newdat<- newdat %>%
mutate(CI_low = pred-cmult*SE) %>%
mutate(CI_high = pred+cmult*SE)
newdat
Then I tried running emmeans on the model to compare my results:
t <- emmeans(model, pairwise ~ Treatment * Species, adjust = "tukey")
t
The results were different enough (no significant pairwise comparisons) that it changes my conclusions substantially.
emmeans
package is well vetted, so if your CI comparison is substantially different from whatemmeans
is telling you I fear that there might be a problem. Consider editing this question to show both types of analyses. Theemmeans
calculations only use the fixed-effect coefficients, but that's usually what you want to evaluate once you've handledGroup
with random intercepts. $\endgroup$emmeans
confidence intervals are t-based, not Z. Useqt(.975, 9)
$\approx$ 2.262 (for df=9) or 2.571 (for df=5) where you used 1.96 (cmult
) and they should match. I do want to reiterate EdM's point that the confidence intervals of the marginal means do not say much about the difference between them - non-overlap is a much more stringent requirement than the CI of their difference excluding zero. $\endgroup$