I am trying to perform a stepwise model with a random effect, of which I can get a BIC value.
The lmerTest package said it works with lme4, but I can only get it to work if I remove one of my independent variables from the model (which is a factor with two options (TM))
The error code is:
Error in
$<-
(*tmp*
, formula, value = Terms) : no method for assigning subsets of this S4 class
or
Error in as_lmerModLmerTest(model) : model not of class 'lmerMod': cannot coerce to class 'lmerModLmerTest
I've read somewhere it might have something to do with the drop1, but I still didn't figure it out. I am also open to suggestions of other packages and functions.
Before, when trying the full.model <- lm ( ... everything worked. After changing to lmer, it didn't anymore.
The code I am using now:
full.model <- lme4::lmer(dep ~ TM + ind + (1 | dorp), data=test) #lmerTest:: give same outcome
step.model<- lmerTest::step(full.model, direction="both",k=log(16)) # n=16
summary(step.model)
BIC(step.model)
#Example dataset
test <- data.frame(TM = as.factor(c(rep("org", 3), rep("min", 3),rep("org", 3), rep("min", 3),rep("org", 3), rep("min", 3))),
dep = runif(18,0,20),
ind = runif(18,0,7),
dorp = as.factor(c(rep(1,6),rep(2,6),rep(3,6))))
lmerTest::lmer(...)
rather thanlme4::lmer(...)
in the first step. Any chance we can have a minimal reproducible example ... ? – Lastditch