I am trying to run ANOVA for binomially distributed data in a data frame named MegaData whose first 4 columns are categorical variable with Unit, Year and species. Below is my R code which isn't working when I try to loop across different columns of the data frame to run my model.
mod <- list()
for (i in MegaData[,5:36]) {
for(j in length(MegaData[,5:36])){
mod[[j]] <- glm(i/number ~ Unit*BeginYear*species_raw,
family = binomial(link = logit), weight=number,
data = MegaData)
print(anova(mod[[j]]), test="Chisq")
print(summary(mod[[j]]))
}
}
If you are trying to train one model for each column in 5:36, obtaining a list of fitted models and printing out the summary of each model, you could try:
Data: