I've found the tidy()
function from the broom
package to be helpful in this type of situation.
here's your model (I cut down to number of iterations to 10 to make it go faster,
also it was throwing warnings using mgcv::gam()
)
a <- c(1:10)
model <- list()
for (i in a) {
model[[i]] <- gam(Species~ s(Petal.Width, bs="cs") +
s(Sepal.Length, bs="cs"),
data = iris,
family = binomial,
method = "REML")
}
If you needed or wanted the list of all the models, then this second loop will extract the statistic
from each model and combine them into a dataframe:
results_df <- data.frame(term=c("Petal.Width","Sepal.Length"))
for(m in model){
results_df <- bind_cols(results_df, model=tidy(m)$statistic)
}
results_df
with output:
term model...2 model...3 model...4 model...5 model...6
1 Petal.Width 1.304372e-09 1.304372e-09 1.304372e-09 1.304372e-09 1.304372e-09
2 Sepal.Length 3.844738e-16 3.844738e-16 3.844738e-16 3.844738e-16 3.844738e-16
model...7 model...8 model...9 model...10 model...11
1 1.304372e-09 1.304372e-09 1.304372e-09 1.304372e-09 1.304372e-09
2 3.844738e-16 3.844738e-16 3.844738e-16 3.844738e-16 3.844738e-16
you can rename the columns to make them nicer, etc.
also you could combine the modeling and the combining of the statistics if that's all you want to keep.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…