简体   繁体   中英

Error in eval(predvars, data, env) : object 'helpfulness' not found

>hyp1.model1<-clmm(helpfulness~reflectiontype+session+(1+reflectiontype|participant),data=hyp1data)
>summary(hyp1.model1) #summary was produced but I won't replicate it here
>anova(hyp1.model1,type="II")
Error in eval(predvars,data,env):object 'helpfulness' not found

I want to run an anova on hyp1.model1 - The model ran fine initially and 'helpfulness' has not come up as a problem in any of my other code using this variable. R has linked with the data set totally fine up until this point and there appears to be no difference between the variable column heading in the data set and the variable label in R (hence all other code has recognised it).

Why is this suddenly a problem when I want to run an anova?

My guess is that helpfulness is not in your data frame hyp1data . When you create the model in your first line, it is found in the local environment (all of the variables you have created in R). However when you run the third line, the code specifically looks for helpfulness in the data frame you have specified. If it isn't there, it would fail like this.

Try:

hyp1data$helpfulness <- helpfulness

Does that fix it?

I ran into the same error, but felt that the answer could be more descriptive. I believe the error arises because the stats::anova() and car::Anova() functions don't have the methods to recognize the ordinal::clmm model.

To run a Cumulative Link Mixed Model with ordinal::clmm() and obtain the follow-up deviance table, make sure to have both the ordinal and RVAideMemoire packages loaded. RVAideMemoire provides the methods to get the deviance table with Anova.clmm() .

# fake data
set.seed(5)
hyp1data <- data.frame(
  participant = c(paste0("id", 1:50),paste0("id", 1:50), paste0("id", 1:50),paste0("id", 1:50)),
  session = c(rep(1, 50), rep(2,50), rep(1, 50), rep(2,50)),
  reflectiontype = c(rep(1, 100), rep(2, 100)),
  helpfulness = sample(1:7, 100, replace = TRUE))

hyp1data[,1:3] <- lapply(hyp1data[,1:3], factor)
hyp1data$helpfulness <- factor(hyp1data$helpfulness, ordered = TRUE)

# load libraries
library(ordinal)
library(RVAideMemoire)

# use RVAideMemoire::Anova.clmm
hyp1.model1<-clmm(helpfulness~reflectiontype+session+(1+reflectiontype|participant),data=hyp1data)
summary(hyp1.model1) 
RVAideMemoire::Anova.clmm(hyp1.model1,type="II")

Just to note another possible solution: I ran into the same problem when my data was called df - somewhere in the function call, this must have gotten confused with the df-function. Renaming my data frame solved it.

I found a way to do an Analysis of Variance using package "RVAideMemoire" and package "car" using the tutorial:

Fabian Bross (2019). Using Mixed Effect Models to Analyze Acceptability Rating Data. Version 1.0. Mimeo. Online: www.fabianbross.de/mixedmodels.pdf.

The section at the end describes very well how to follow up a clmm model in this way.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM