I'm a rookie in R Studio and don't know how to make a reproducible example of this, but I hope you get the hang of it:
I have two lists, model1_list
and model2_list
that both include 47 model outputs for ERGMs. I want to compare each model with their counterpart model in the other list like this
anova(model1_list[[1]], model2_list[[1]])
However, I cannot come up with a solution to loop all of the anova()
tests at once. I've tried
anova_m1_m2 <- list
for(i in c(1:47)){
m1 <- model1_list[[i]]
m2 <- model2_list[[i]]
a_m1_m2 <- anova(m1, m2)
anova_m1_m2[[(i)]] <- a_m1_m2
}
But get the error message
Error in anova_m1_m2[[(i)]] <- a_m1_m2 : object of type 'builtin' is not subsettable
Any ideas?
CodePudding user response:
Fix it to anova_m1_m2 <- list()
, or better:
vector(mode = "list", length = length(model1_list))
Or simply do
anova_m1_m2 <- Map(anova, model1_list, model2_list)