Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

r - bug in lme4 package with anova()

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)

enter image description here enter image description here

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).

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The accepted solution (explicitly call 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 ...)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...