I am trying to map multiple models over some data and store the results in something similar to a nested tibble or multiple lists. I would like to apply the models in the same pipe. I run the following:
data(iris)
df <- iris %>%
filter(Species != "setosa") %>%
mutate(Species = +(Species == "virginica"))
var_combos <- expand.grid(colnames(df[,1:4]), colnames(df[,1:4])) %>%
filter(!Var1 == Var2)
map2(
.x = var_combos$Var1,
.y = var_combos$Var2,
~select(df, .x, .y) %>%
mutate(
Species = df$Species
)
) %>%
map(., ~glm(Species ~ ., data = ., family = binomial(link='logit')))
Which gets me a nice maps logistic model. How can I store this model in a nested tibble or a list and then mutate
and add more models to be stored next to it, such as:
... %>%
map(., ~glm(Species ~ ., data = ., family = binomial(link='logit'))) %>%
map(., e1071::svm(Species ~ ., data = ., kernel = "polynomial"))