Error in eval(predvars, data, env) : object 'CO2.f' not found when doing an Anova

Cross-posted to r - Error in eval(predvars, data, env) : object 'CO2.f' not found when doing an Anova - Stack Overflow


I'm trying to perform an repeated measurements ANOVA from my field data (field_data) with the following code:

#First convert variables into factors:
field_data$month = factor(field_data$month,
                          levels=unique(field_data$month))

field_data$distance = factor(field_data$distance)

field_data$CO2.f = factor(field_data$CO2,
                          ordered = TRUE)
# Model
model_CO2 = clmm(CO2.f ~ month + distance + month:distance + (1|nest),
                 data = field_data,
                 threshold = "equidistant")

# Anova of the model
Anova(model_CO2,
      type = "II")

I've run the same code for a couple of weeks without any problems, but today when I tried to run it again I got some errors: everything seems to work fine until I make the model, but when I run the Anova I get the following message:

Error in eval(predvars, data, env) : object 'CO2.f' not found

I've run:

is.data.frame(field_data)

and also tried to change the excel where I have my data, but nothing seems to work out.

Any ideas?

Thanks!

Update:
I've tried to run this in another computer and it seems to work fine. Does anyone have an idea why this is happening?

Update 2:

When I run the model_CO2, I get results:

Cumulative Link Mixed Model fitted with the Laplace approximation

formula: CO2.f ~ month + distance + month:distance + (1 | nest)
data:    field_data

 link  threshold   nobs logLik  AIC     niter      max.grad
 logit equidistant 123  -551.68 1137.36 1213(4936) 5.30e-04

Random effects:
 Groups Name        Variance Std.Dev.
 nest   (Intercept) 3.521    1.876   
Number of groups:  nest 5 

Coefficients:
                    monthjuly                monthseptember                distance0.25 m 
                      -1.1232                        1.6078                        0.4056 
                distance0.5 m                distance0.75 m                   distance1 m 
                       2.5090                        0.6062                        2.5836 
     monthjuly:distance0.25 m monthseptember:distance0.25 m       monthjuly:distance0.5 m 
                       0.2939                       -0.3551                       -1.2597 
 monthseptember:distance0.5 m      monthjuly:distance0.75 m monthseptember:distance0.75 m 
                      -1.7791                        0.3966                        0.4520 
        monthjuly:distance1 m    monthseptember:distance1 m 
                      -1.4307                       -0.7867 

Thresholds:
threshold.1     spacing 
   -3.61618     0.08347 

This is why I think it has something to do with the ANOVA and not with the factor. However, I've tried other kinds of ANOVA (to see if the problem was one library) and I keep getting the same error.

Hi @bivanezb,
Welcome to the RStudio Community Forum.

Looks like there is a problem with the columns of your data frame.
Have you checked:

head(field_data)
str(field_data)

Do you see what you expect?

I checked:

library(ordinal)
help("clmm")
data(wine)
data(soup)
str(wine)
str(soup)

# In those clmm() examples, response variables are ordered factors but 
# with character labels for their levels.
# So, in your situation you *may* need

field_data$CO2.f <- factor(field_data$CO2, 
                           ordered=TRUE, 
                           labels=c("xx","yy","zz"))

HTH

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.