'Tidyverse map glms with different formulas
I'm trying to fit multiple GLMs to the same data, but with different formulas. But, with my current code it's only fitting the first formula each time. Please advise, thanks!
lungs = url('http://users.stat.ufl.edu/~aa/cat/data/Lungs.dat') %>%
read_table(col_types = 'ffiic') %>%
select(-X5)
models = tibble(model = c('City', 'Smoking', 'City + Smoking', 'City * Smoking')) %>%
mutate(fit = map(model, ~glm(as.formula(paste0('Yes / (Yes + No) ~ ', model)), family=binomial, weights=Yes+No, data=lungs)),
glanced = map(fit, glance),
tidied = map(fit, tidy)) %>%
unnest(glanced)
models
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
