I would like to use lme4
to fit a mixed effects regression and multcomp
to compute the pairwise comparisons. I have a complex data set with multiple continuous and categorical predictors, but my question can be demonstrated using the built-in ChickWeight
data set as an example:
m <- lmer(weight ~ Time * Diet + (1 | Chick), data=ChickWeight, REML=F)
Time
is continuous and Diet
is categorical (4 levels) and there are multiple Chicks per diet. All the chicks started out at about the same weight, but their diets (may) affect their growth rate, so the Diet
intercepts should be (more or less) the same, but the slopes might be different. I can get the pairwise comparisons for the intercept effect of Diet
like this:
summary(glht(m, linfct=mcp(Diet = "Tukey")))
and, indeed, they are not significantly different, but how can I do the analogous test for the Time:Diet
effect? Just putting the interaction term into mcp
produces an error:
summary(glht(m, linfct=mcp('Time:Diet' = "Tukey")))
Error in summary(glht(m, linfct = mcp(`Time:Diet` = "Tukey"))) :
error in evaluating the argument 'object' in selecting a method for function
'summary': Error in mcp2matrix(model, linfct = linfct) :
Variable(s) ‘Time:Diet’ have been specified in ‘linfct’ but cannot be found in ‘model’!
Time*Diet
, which is just a simplification ofTime + Diet + Time:Diet
. Usinganova(m)
orsummary(m)
confirms that the interaction term is in the model. $\endgroup$