runehaubo / lmerTestR

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

step fails when random effects are eliminated by reduce.random #23

Closed bbolker closed 3 years ago

bbolker commented 5 years ago

When all random effects are removed at the reduce.random stage, the resulting object is of class lm rather than merMod, and can't be converted to an lmerModLmerTest object. At a quick glance it looks like older versions may have had a fix for this case, i.e. passing the resulting object on to stats::step ...

https://stackoverflow.com/questions/55638476/how-to-do-stepwise-model-with-random-effect-lme4-lmertest

set.seed(101)
test <- data.frame(TM = factor(rep(rep(c("org","min"),each=3),3)),
                   dep = runif(18,0,20),
                   ind = runif(18,0,7),
                   dorp = factor(rep(1:3,each=6)))
library(lmerTest)
full.model <- lmer(dep ~ TM + ind + (1 | dorp),  data=test)
step(full.model)

Error in as_lmerModLmerTest(model) : model not of class 'lmerMod': cannot coerce to class 'lmerModLmerTest step.model<- lmerTest::step(full.model, direction="both",k=log(16))

runehaubo commented 3 years ago

It only took us 1.5 years + 10 min to fix this issue :-) Thanks for reporting!

Cheers Rune