Reputation: 11
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:
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)
Upvotes: 1
Views: 692
Reputation: 226162
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
Upvotes: 2