runehaubo / lmerTestR

Repository for the R-package lmerTest
48 stars 9 forks source link

testing random effects #12

Closed mattansb closed 6 years ago

mattansb commented 6 years ago

While using ranova I've found that it behaves in a manner I was not expecting, and I'm not sure if this is a bug or if I've misunderstood something.

If I run this:

fm1 <- lmer(Reaction ~ Days + (Days|Subject), sleepstudy)
ranova(fm1)

I expect to get a test where both the random effect of days and the random (Intercept) are tested, but instead only the random effect from Days is tested. Is this the correct behavior of ranova? Is there another way get both together in one output?

runehaubo commented 6 years ago

It's not a bug, but documented behaviour: help(ranova) says "A random-effect term of the form (f1 | gr) is reduced to (1 | gr)" and this is exactly what you see. Though ranova in general may not generate all tests of interest (see the examples in help(ranova)) I think in this case it produces the relevant tests; it does not make sense to remove the intercept while keeping the random slope for Subject. Also note that the test for slope is on 2 df since the covariance parameter between the random intercepts and slopes is removed along with the random slopes.

Models such as

 lmer(Reaction ~ Days + (0 + Days|Subject), sleepstudy)
 lmer(Reaction ~ Days + (1|Subject) + (0 + Days|Subject), sleepstudy)

do not make sense in general so ranova will not fit and compare them.