rlme4r-car

Using car:::linearHypothesis() with lme4 models


I want to test whether a coefficient (not the intercept) from a mixed effects model fit using lme4:::lmer() is different from a value other than zero. car:::linearHypothesis() should be able to do this, with p-values and error degrees of freedom calculated using a Kenward-Rogers approximation, as implemented in pbkrtest (car documentation; pbkrtest documentation).

However, I've run into what I think is a bug. I only seem to be able to obtain tests of the coefficient of interest against 0. Here's a reproducible example:

library(car)
library(lme4)
library(pbkrtest)

set.seed(32432)

d <- data.frame(id=rep(1:100, 4), x=rnorm(400), y=rnorm(400))
m <- lmer(y ~ x + (1|id), data=d)

linearHypothesis(m, "x=4", test="F")
# F=.1256, p=.7232
linearHypothesis(m, "x=0", test="F")
# F=.1256, p=.7232

Clearly these F and p-values should not be the same!

For reference, I don't get the same bug if I use $\Chi^2$ tests, which suggests to me that the bug is pbkrtest:

linearHypothesis(m, "x=4")
# X2=5614.1, p=2.2e-16
linearHypothesis(m, "x=0")
# X2=.1268, p=.7218

Anyone have a workaround?


Solution

  • I contacted John Fox, the author of the car package. He confirmed that there is indeed a bug in how car:::linearHypothesis() treats models fit with lme4:::lmer(). This should be fixed in the next version of car.