Skip to contents

fit_multiverse() applies a fitting function to each row of a specification grid and returns a tidy tibble with one row per returned model term per specification. Because the fits are independent, they can run in parallel via furrr when .parallel = TRUE.

Usage

fit_multiverse(specs, .f, ..., .parallel = FALSE, .seed = NULL)

Arguments

specs

A specification grid, for example from spec_grid() or adjuster_sets().

.f

A function (or a purrr-style formula) applied to each specification. It receives one row of specs as a one-row tibble; access columns with spec$col, for example spec$adjusters[[1]] for the output of adjuster_sets(). It should return a tibble, for example from broom::tidy().

...

Additional arguments passed on to .f.

.parallel

Logical; fit across cores with furrr. Set a plan first with future::plan().

.seed

Optional integer seed for reproducible parallel fits.

Value

specs with the tidy model output unnested: one row per returned term per specification, in the original grid order.

Examples

if (FALSE) { # \dontrun{
specs <- adjuster_sets(c("age", "sex", "bmi"))
fit_multiverse(specs, function(spec) {
  f <- reformulate(c("exposure", spec$adjusters[[1]]), "outcome")
  broom::tidy(lm(f, data = df), conf.int = TRUE)
})
} # }