在 lmer 输出上运行 car Anova 后列出类型错误 [英] List type error after running car Anova on lmer output

查看:30
本文介绍了在 lmer 输出上运行 car Anova 后列出类型错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 R 中创建随机效应模型.我想在输出上运行 anova,我已经浏览了一些教程并复制了他们的示例,但我的不是在职的.我在 Anova 上不断收到以下错误:

I'm trying to do a random effects model in R. I want to run an anova on the output, I've looked through a few tutorials and copied their examples but mine isn't working. I keep getting the following error on the Anova:

(1:length(names))[-which.term][sapply(names[-which.term],function(term2) is.relative(term, : 无效的下标类型 'list'

Error in (1:length(names))[-which.term][sapply(names[-which.term], function(term2) is.relative(term, : invalid subscript type 'list'

我正在运行的代码如下,任何人对问题的任何想法都将不胜感激!

The code I'm running is below, any ideas anyone has on what the problem is would be most appreciated!

library(lme4)
library(car)

div1<-rep(1,5)
div2<-rep(2,3)
div3<-rep(3,3)
div6<-rep(6,6)
div<-c(div1,div2,div3,div6)
res<-c(3.8082479,7.7819745,3.3792467,7.2288647,3.4564646,1.8043898,5.1443293,3.9467614,2.5922306,1.9996585,4.2004104,0.7290807,2.1854365,3.4118980,3.2464388,2.9607496,1.9993038)
df<-data.frame(div,res)

randeff<-lmer(res~1+(1|div),data=df,REML=FALSE)
summary(randeff)
Anova(randeff)

推荐答案

car::Anova 仅用于分析固定效应.你试图分析一个没有随机效应的模型,所以它很不高兴(不幸的是,错误消息是高深莫测的).要检验这个假设,请向您的数据集添加一个随机列并对模型添加一个固定效应:

car::Anova is designed for analyzing fixed effects only. You tried to analyze a model with no random effects, so it got unhappy (unfortunately, the error message was inscrutable). To test this hypothesis, add a random column to your data set and a fixed effect to the model:

> df$y <- rnorm(nrow(df))
> randeff2 <- lmer(res~y+(1|div),data=df,REML=FALSE)
> Anova(randeff2)
Analysis of Deviance Table (Type II Wald chisquare tests)

Response: res
   Chisq Df Pr(>Chisq)
y 0.0418  1      0.838

这篇关于在 lmer 输出上运行 car Anova 后列出类型错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆