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.

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.

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)
#> # A tibble: 90 × 12
#>    .sim_id     n   rep Source     a     b .fitted .resid .std.re…¹   .hat .sigma
#>      <int> <dbl> <int> <chr>  <int> <dbl>   <dbl>  <dbl>     <dbl>  <dbl>  <dbl>
#>  1       1    40     1 logit      1 1.14   -0.919  1.58      1.61  0.0304   1.12
#>  2       1    40     1 logit      1 1.88   -0.764  1.51      1.53  0.0259   1.12
#>  3       1    40     1 logit      0 0.653  -1.02  -0.784    -0.799 0.0370   1.15
#>  4       1    40     1 logit      1 4.26   -0.261  1.29      1.34  0.0713   1.13
#>  5       1    40     1 logit      1 1.18   -0.911  1.58      1.60  0.0300   1.12
#>  6       1    40     1 logit      0 1.64   -0.815 -0.856    -0.868 0.0265   1.14
#>  7       1    40     1 logit      0 6.10    0.127 -1.23     -1.36  0.174    1.13
#>  8       1    40     1 logit      0 1.46   -0.853 -0.843    -0.855 0.0276   1.14
#>  9       1    40     1 logit      1 1.33   -0.879  1.57      1.59  0.0285   1.12
#> 10       1    40     1 logit      0 1.82   -0.776 -0.870    -0.882 0.0259   1.14
#> # … with 80 more rows, 1 more variable: .cooksd <dbl>, and abbreviated variable
#> #   name ¹​.std.resid

## Arguments to the function can be passed in ...
logit_fit %>%
  apply_fits(broom::augment, se_fit = TRUE)
#> # A tibble: 90 × 13
#>    .sim_id     n   rep Source     a     b .fitted .se.fit .resid .std.r…¹   .hat
#>      <int> <dbl> <int> <chr>  <int> <dbl>   <dbl>   <dbl>  <dbl>    <dbl>  <dbl>
#>  1       1    40     1 logit      1 1.14   -0.919   0.386  1.58     1.61  0.0304
#>  2       1    40     1 logit      1 1.88   -0.764   0.345  1.51     1.53  0.0259
#>  3       1    40     1 logit      0 0.653  -1.02    0.436 -0.784   -0.799 0.0370
#>  4       1    40     1 logit      1 4.26   -0.261   0.539  1.29     1.34  0.0713
#>  5       1    40     1 logit      1 1.18   -0.911   0.383  1.58     1.60  0.0300
#>  6       1    40     1 logit      0 1.64   -0.815   0.353 -0.856   -0.868 0.0265
#>  7       1    40     1 logit      0 6.10    0.127   0.837 -1.23    -1.36  0.174 
#>  8       1    40     1 logit      0 1.46   -0.853   0.363 -0.843   -0.855 0.0276
#>  9       1    40     1 logit      1 1.33   -0.879   0.371  1.57     1.59  0.0285
#> 10       1    40     1 logit      0 1.82   -0.776   0.347 -0.870   -0.882 0.0259
#> # … with 80 more rows, 2 more variables: .sigma <dbl>, .cooksd <dbl>, and
#> #   abbreviated variable name ¹​.std.resid

## Using a purrr-style lambda function
logit_fit %>%
  apply_fits(~ summary(.)$cov.scaled)
#> # A tibble: 4 × 6
#>   .sim_id     n   rep Source `(Intercept)`       b
#>     <int> <dbl> <int> <chr>          <dbl>   <dbl>
#> 1       1    40     1 logit         0.272  -0.0744
#> 2       1    40     1 logit        -0.0744  0.0359
#> 3       2    50     1 logit         0.359  -0.167 
#> 4       2    50     1 logit        -0.167   0.102