apply_fits {simpr}R Documentation

Run a given function or formula expression on a simpr_mod object and tidy the output.

Description

This function applies a given function to all fit objects and returns the result in a tidy tibble. Any function or purrr-style lambda function can be used.

Usage

apply_fits(obj, .f, ..., .progress = FALSE, .options = furrr_options())

Arguments

obj

a simpr_tibble with repetition number, metaparameters, simulated data, and fitted models, from fit

.f

A function or purrr-style lambda function (see as_mapper) used for computing on the fit object

...

Additional arguments to .f.

.progress

A logical, for whether or not to print a progress bar for multiprocess, multisession, and multicore plans .

.options

The future specific options to use with the workers when using futures. This must be the result from a call to furrr_options().

Value

A tibble with columns .sim_id, rep, Source (which contains the name of the fit column), any metaparameters from define, and additional columns containing the results of .f applied to each fit object.

See Also

tidy_fits, glance_fits

Examples

set.seed(100)
logit_fit = specify(a = ~ sample(0:1, size = n, replace = TRUE),
        b = ~ a + rlnorm(n)) %>%
  define(n = c(40, 50)) %>%
  generate(1) %>%
  fit(logit = ~ glm(a ~ b, family = "binomial"))

logit_fit %>%
  apply_fits(broom::augment)

## Arguments to the function can be passed in ...
logit_fit %>%
  apply_fits(broom::augment, se_fit = TRUE)

## Using a purrr-style lambda function
logit_fit %>%
  apply_fits(~ summary(.)$cov.scaled)


[Package simpr version 0.2.6 Index]