library(Matrix)
library(lme4)
data <- lme4::sleepstudy
model1 <- lm(Reaction ~ Days, data = data)
model2 <- lmer(Reaction ~ 1+Days+(1+Days|Subject), data = data)
summary(model1)
summary(model2)
anova(model1, model2)
So I needed to update R to 4.0.2 and now comparing mixed effects models using the anova
function returns an error. The error seems to appear when I assign the model because in the global environment it says "object with null pointer". The error seems only to appear using lmer
and not with lm
. Can anybody tell me how to fix this? I need at least R version 4.0.0 (my professor writes scripts that require this version).
Explicitly calling lme4::anovaLmer()
works, but the actual problem here is that if you want to run anova()
comparing a(n) [g]lm
model and a(n) [g]lmer
model, you need to put the [g]lmer model first in the list of arguments, <because ... boring technical details: S3 method dispatch blah blah blah ...>. (This should be documented, and isn't that I can tell.) For your example,
anova(model2,model1)
works fine!
The "object with null pointer" error is a red herring: unrelated, mysterious, probably RStudio-related, see also this question and this question (neither is answered ...)