[R-sig-ME] lme4: Parameter contrasts?

Hufthammer, Karl Ove karl.ove.hufthammer at helse-bergen.no
Thu Feb 5 13:12:17 CET 2015

Tom Carpenter wrote:
> Hoping someone has some advice here. I recently made the switch from using
> HLM to lmer. I know that in HLM, you could do a parameter contrast (e.g., contrast
> two fixed effects against each other and test the significance of the contrast).
> I was curious if anyone knows how to do this in R

There are at least four options:

the multcomp package
estimable() in the gmodels package
the lsmeans package
the contrast package

Some of these work with nlme models (lme and/or gls) and some with lme4 models, and some with both (and with other type of models, e.g. GEE models). Some of them can adjust for multiple comparisons. They all give slightly different answers, even when not adjusting for multiple comparisons. I think this is mostly related to treating the degrees of freedom differently:

multcomp uses asymptotic tests («infinite» degrees of freedom, z-tests) for everything except normal linear (non mixed-effects models), where it uses ordinary t-tests. (It even uses z-tests for gls models, though I think this shouldn’t be necessary.) It has excellent support for adjusting for multiple comparisons, in a variety of ways.

estimable() uses the *minimum* of the degrees of freedom of the parameters of the chosen contract when testing and constructing confidence intervals.

lsmeans uses asymptotic tests for lme(r) models, but calculates the correct (?) degrees of freedom for gls and lm objects. (In a simple gls example I tested, it seemed to sum the degrees of freedom.) It also supports the multcomp package.

contrast calculates degrees of freedom for both lme and gls models. However, the calculated degrees of freedom seems to differ between what I believe should basically be equivalent lme and gls models (e.g., a two time-point longitudinal gls model with compound symmetry and a mixed effects model with a random intercept for subject).

Karl Ove Hufthammer

More information about the R-sig-mixed-models mailing list