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 |
.f |
A function or |
... |
Additional arguments to |
.progress |
A logical, for whether or not to print a progress bar for multiprocess, multisession, and multicore plans . |
.options |
The |
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
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)