When I run the following code, I get an error: "object 'modelB' not found"
sim_analysis <- function(temp_data) {
  modelA <- clmm("Item1 ~ Total + (1 | Clust)", data = temp_data)
  modelB <- clmm("Item1 ~ Total + Group + (1 | Clust)", data = temp_data)
  return(anova(modelA, modelB)$`Pr(>Chisq)`[2])
}
sim_analysis(my_data)
But when I step through the function for temp_data = data, I get no error:
temp_data <- my_data
modelA <- clmm("Item1 ~ Total + (1 | Clust)", data = temp_data)
modelB <- clmm("Item1 ~ Total + Group + (1 | Clust)", data = temp_data)
anova(modelA, modelB)$`Pr(>Chisq)`[2]
The problem must have something to do with clmm (from the ordinal package) because when I make Item1 responses numeric, remove the random effects, and do the exact same thing with lm, the function works fine.
A reproducible example was asked for, so here is some code to generate the data:
set.seed(12345678)
my_data <- data.frame(Clust = c(rep(1, 10), rep(2, 10), rep(3, 10)),
                        Group = rep(c(0,1), 15),
                        Item1 = as.factor(sample(c(1, 2, 3, 4), 30, replace = TRUE)),
                        Total = sample(20:50, 30, replace = TRUE))
