I have a list of over ~100 linear models and I want to take the estimated means and standard errors for each model.
Let's use mtcars as an example.
library(tidyverse); library(magrittr); library(emmeans)
mtcars %<>%
mutate(
cyl = as.factor(cyl)
)
df <- mtcars %>% select(cyl, hp, mpg)
I can easily get the estimated means and standard errors for each model with emmeans:
mod <- lm(hp ~ cyl, data = df)
emmeans(mod, "cyl")
But what if I have a list of models?
list_lm <- df %>%
select(-c(cyl)) %>%
map(function(dv) lm(dv ~ df$cyl, data = .))
I cannot use:
emmeans(list_lm$hp, "cyl")
Error in ref_grid(object, ...) : Perhaps a 'data' or 'params' argument is needed
And ideally, I want something that would give me these statistics for all the models. Something like broom::tidy for the coefficients of the model, but for emmeans:
list_lm %>%
map(broom::tidy)