带有anova()的lme4软件包中的错误 [英] 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)
所以我需要将R更新到4.0.2,现在使用 anova
函数比较混合效果模型会返回错误.当我分配模型时,似乎出现了错误,因为在全局环境中,它说带空指针的对象".该错误似乎仅使用 lmer
出现,而不是使用 lm
.谁能告诉我该如何解决?我至少需要R版本4.0.0(我的教授写的脚本需要此版本).
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).
推荐答案
可接受的解决方案(明确地调用 lme4 :: anovaLmer()
)有效,但是这里的实际问题是,如果您想运行 anova()
比较一个(n) [g] lm
模型和一个(n) [g] lmer
模型,您需要将[g] lmer模型放在参数列表中,因为<因为无聊的技术细节:S3方法调度等等等等.(这应该记录在案,不是我能告诉的.)对于您的示例,
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)
工作正常!
具有空指针的对象";错误是红色鲱鱼:无关,神秘,可能与RStudio有关,另请参见问题和
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 ...)
这篇关于带有anova()的lme4软件包中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!