Skip to contents

Applies a tidying function (default broom.mixed::tidy) to a column of models, returning a tidy data frame with one row per term per model, suitable for downstream summarisation and evaluation in simulation studies.

Usage

extract_model_results(
  models,
  model_col = model,
  tidy_fun = broom.mixed::tidy,
  .term = NULL
)

Arguments

models

A data frame containing a column of fitted model objects.

model_col

Unquoted column name containing the models. Default is model.

tidy_fun

A tidying function to apply to each model. Default is broom.mixed::tidy. The function must return a data frame with a term column.

.term

Optional string specifying a term to filter after tidying (e.g., "(Intercept)"). If NULL (default), all terms are retained.

Value

A tidy data frame with the original columns of models joined to the tidied model results, typically including columns such as term, estimate, std.error, statistic, and p.value.

Examples

library(dplyr)
#> Error in library(dplyr): there is no package called ‘dplyr’
library(purrr)
library(broom.mixed)
#> Error in library(broom.mixed): there is no package called ‘broom.mixed’

# Simulate and fit models
sim_models <- tibble(
  id = 1:5,
  model = map(1:5, ~ lm(mpg ~ wt, data = mtcars))
)
#> Error in tibble(id = 1:5, model = map(1:5, ~lm(mpg ~ wt, data = mtcars))): could not find function "tibble"

# Extract all terms
extract_model_results(sim_models)
#> Error in loadNamespace(x): there is no package called ‘tidyr’

# Extract only the slope term
extract_model_results(sim_models, .term = "wt")
#> Error in loadNamespace(x): there is no package called ‘tidyr’