Applies a modeling function to every combination of a set of formulas and a set of data subsets.

cross_fit(
  data,
  formulas,
  cols = NULL,
  weights = NULL,
  clusters = NULL,
  families = NULL,
  fn = lm,
  fn_args = list(),
  tidy = tidy_glance,
  tidy_args = list(),
  errors = c("stop", "warn")
)

Arguments

data

A data frame

formulas

A list of formulas to apply to each subset of the data. If named, these names will be used in the model column of the output. Otherwise, the formulas will be converted to strings in the model column.

cols

Columns to subset the data. Can be any expression supported by <tidy-select>. If NULL, the data is not subset into columns. Defaults to NULL.

weights

A list of columns passed to weights in fn. If one of the elements is NULL or NA, that model will not be weighted. Defaults to NULL.

clusters

A list of columns passed to clusters if supported by fn. If one of the elements is NULL or NA, that model will not be clustered. Defaults to NULL.

families

A list of glm model families passed to family if supported by fn. Defaults to gaussian("identity"), the equivalent of lm(). See family for examples.

fn

The modeling function. Either an unquoted function name or a purrr-style lambda function with two arguments. To use multiple modeling functions, see cross_fit_glm(). Defaults to lm.

fn_args

A list of additional arguments to fn.

tidy

A logical or function to use to tidy model output into data.frame columns. If TRUE, uses the default tidying function: tidy_glance(). If FALSE, NA, or NULL, the untidied model output will be returned in a list column named fit. An alternative function can be specified with an unquoted function name or a purrr-style lambda function with one argument (see usage with broom::tidy(conf.int = TRUE) in examples). Defaults to tidy_glance.

tidy_args

A list of additional arguments to the tidy function

errors

If "stop", the default, the function will stop and return an error if any subset produces an error. If "warn", the function will produce a warning for subsets that produce an error and return results for all subsets that do not.

Value

A tibble with a column for the model formula, columns for subsets, columns for the model family and type (if applicable), columns for the weights and clusters (if applicable), and columns of tidy model output or a list column of models (if tidy = FALSE)

See also

cross_fit_glm() to map a model across multiple model types.

cross_fit_robust() to map robust linear models.

xmap() to apply any function to combinations of inputs.

Examples

cross_fit(mtcars, mpg ~ wt, cyl)
#> # A tibble: 6 × 19
#>   model      cyl term      estim…¹ std.e…² stati…³ p.value r.squ…⁴ adj.r…⁵ sigma
#>   <chr>    <dbl> <chr>       <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl> <dbl>
#> 1 mpg ~ wt     4 (Interce…   39.6    4.35     9.10 7.77e-6   0.509   0.454  3.33
#> 2 mpg ~ wt     4 wt          -5.65   1.85    -3.05 1.37e-2   0.509   0.454  3.33
#> 3 mpg ~ wt     6 (Interce…   28.4    4.18     6.79 1.05e-3   0.465   0.357  1.17
#> 4 mpg ~ wt     6 wt          -2.78   1.33    -2.08 9.18e-2   0.465   0.357  1.17
#> 5 mpg ~ wt     8 (Interce…   23.9    3.01     7.94 4.05e-6   0.423   0.375  2.02
#> 6 mpg ~ wt     8 wt          -2.19   0.739   -2.97 1.18e-2   0.423   0.375  2.02
#> # … with 9 more variables: model.statistic <dbl>, model.p.value <dbl>,
#> #   df <dbl>, logLik <dbl>, AIC <dbl>, BIC <dbl>, deviance <dbl>,
#> #   df.residual <int>, nobs <int>, and abbreviated variable names ¹​estimate,
#> #   ²​std.error, ³​statistic, ⁴​r.squared, ⁵​adj.r.squared
cross_fit(mtcars, list(mpg ~ wt, mpg ~ hp), cyl)
#> # A tibble: 12 × 19
#>    model      cyl term   estimate std.e…¹ stati…² p.value r.squ…³ adj.r.…⁴ sigma
#>    <chr>    <dbl> <chr>     <dbl>   <dbl>   <dbl>   <dbl>   <dbl>    <dbl> <dbl>
#>  1 mpg ~ wt     4 (Inte… 39.6      4.35     9.10  7.77e-6  0.509   0.454    3.33
#>  2 mpg ~ wt     4 wt     -5.65     1.85    -3.05  1.37e-2  0.509   0.454    3.33
#>  3 mpg ~ wt     6 (Inte… 28.4      4.18     6.79  1.05e-3  0.465   0.357    1.17
#>  4 mpg ~ wt     6 wt     -2.78     1.33    -2.08  9.18e-2  0.465   0.357    1.17
#>  5 mpg ~ wt     8 (Inte… 23.9      3.01     7.94  4.05e-6  0.423   0.375    2.02
#>  6 mpg ~ wt     8 wt     -2.19     0.739   -2.97  1.18e-2  0.423   0.375    2.02
#>  7 mpg ~ hp     4 (Inte… 36.0      5.20     6.92  6.93e-5  0.274   0.193    4.05
#>  8 mpg ~ hp     4 hp     -0.113    0.0612  -1.84  9.84e-2  0.274   0.193    4.05
#>  9 mpg ~ hp     6 (Inte… 20.7      3.30     6.26  1.53e-3  0.0161 -0.181    1.58
#> 10 mpg ~ hp     6 hp     -0.00761  0.0266  -0.286 7.86e-1  0.0161 -0.181    1.58
#> 11 mpg ~ hp     8 (Inte… 18.1      2.99     6.05  5.74e-5  0.0804  0.00382  2.56
#> 12 mpg ~ hp     8 hp     -0.0142   0.0139  -1.02  3.26e-1  0.0804  0.00382  2.56
#> # … with 9 more variables: model.statistic <dbl>, model.p.value <dbl>,
#> #   df <dbl>, logLik <dbl>, AIC <dbl>, BIC <dbl>, deviance <dbl>,
#> #   df.residual <int>, nobs <int>, and abbreviated variable names ¹​std.error,
#> #   ²​statistic, ³​r.squared, ⁴​adj.r.squared
cross_fit(mtcars, list(wt = mpg ~ wt, hp = mpg ~ hp), cyl)
#> # A tibble: 12 × 19
#>    model   cyl term      estimate std.e…¹ stati…² p.value r.squ…³ adj.r.…⁴ sigma
#>    <chr> <dbl> <chr>        <dbl>   <dbl>   <dbl>   <dbl>   <dbl>    <dbl> <dbl>
#>  1 wt        4 (Interce… 39.6      4.35     9.10  7.77e-6  0.509   0.454    3.33
#>  2 wt        4 wt        -5.65     1.85    -3.05  1.37e-2  0.509   0.454    3.33
#>  3 wt        6 (Interce… 28.4      4.18     6.79  1.05e-3  0.465   0.357    1.17
#>  4 wt        6 wt        -2.78     1.33    -2.08  9.18e-2  0.465   0.357    1.17
#>  5 wt        8 (Interce… 23.9      3.01     7.94  4.05e-6  0.423   0.375    2.02
#>  6 wt        8 wt        -2.19     0.739   -2.97  1.18e-2  0.423   0.375    2.02
#>  7 hp        4 (Interce… 36.0      5.20     6.92  6.93e-5  0.274   0.193    4.05
#>  8 hp        4 hp        -0.113    0.0612  -1.84  9.84e-2  0.274   0.193    4.05
#>  9 hp        6 (Interce… 20.7      3.30     6.26  1.53e-3  0.0161 -0.181    1.58
#> 10 hp        6 hp        -0.00761  0.0266  -0.286 7.86e-1  0.0161 -0.181    1.58
#> 11 hp        8 (Interce… 18.1      2.99     6.05  5.74e-5  0.0804  0.00382  2.56
#> 12 hp        8 hp        -0.0142   0.0139  -1.02  3.26e-1  0.0804  0.00382  2.56
#> # … with 9 more variables: model.statistic <dbl>, model.p.value <dbl>,
#> #   df <dbl>, logLik <dbl>, AIC <dbl>, BIC <dbl>, deviance <dbl>,
#> #   df.residual <int>, nobs <int>, and abbreviated variable names ¹​std.error,
#> #   ²​statistic, ³​r.squared, ⁴​adj.r.squared

cross_fit(mtcars, list(mpg ~ wt, mpg ~ hp), c(cyl, vs))
#> Warning: essentially perfect fit: summary may be unreliable
#> Warning: essentially perfect fit: summary may be unreliable
#> Warning: essentially perfect fit: summary may be unreliable
#> # A tibble: 20 × 20
#>    model      cyl    vs term   estimate  std.error  statistic    p.value r.squ…¹
#>    <chr>    <dbl> <dbl> <chr>     <dbl>      <dbl>      <dbl>      <dbl>   <dbl>
#>  1 mpg ~ wt     4     0 (Inte…  26      NaN        NaN        NaN         0     
#>  2 mpg ~ wt     4     0 wt      NA       NA         NA         NA         0     
#>  3 mpg ~ wt     4     1 (Inte…  39.9      4.61e+ 0   8.66e+ 0   2.47e- 5  0.520 
#>  4 mpg ~ wt     4     1 wt      -5.72     1.95e+ 0  -2.94e+ 0   1.87e- 2  0.520 
#>  5 mpg ~ wt     6     0 (Inte…  22.2      1.61e+ 1   1.38e+ 0   3.99e- 1  0.0103
#>  6 mpg ~ wt     6     0 wt      -0.594    5.83e+ 0  -1.02e- 1   9.35e- 1  0.0103
#>  7 mpg ~ wt     6     1 (Inte…  63.6      1.19e+ 1   5.36e+ 0   3.30e- 2  0.876 
#>  8 mpg ~ wt     6     1 wt     -13.1      3.50e+ 0  -3.75e+ 0   6.42e- 2  0.876 
#>  9 mpg ~ wt     8     0 (Inte…  23.9      3.01e+ 0   7.94e+ 0   4.05e- 6  0.423 
#> 10 mpg ~ wt     8     0 wt      -2.19     7.39e- 1  -2.97e+ 0   1.18e- 2  0.423 
#> 11 mpg ~ hp     4     0 (Inte…  26      NaN        NaN        NaN         0     
#> 12 mpg ~ hp     4     0 hp      NA       NA         NA         NA         0     
#> 13 mpg ~ hp     4     1 (Inte…  36.0      5.52e+ 0   6.52e+ 0   1.85e- 4  0.273 
#> 14 mpg ~ hp     4     1 hp      -0.113    6.55e- 2  -1.73e+ 0   1.21e- 1  0.273 
#> 15 mpg ~ hp     6     0 (Inte…  23.2      1.98e-14   1.17e+15   5.43e-16  1     
#> 16 mpg ~ hp     6     0 hp      -0.0200   1.46e-16  -1.37e+14   4.66e-15  1     
#> 17 mpg ~ hp     6     1 (Inte…  24.2      1.41e+ 1   1.72e+ 0   2.28e- 1  0.0613
#> 18 mpg ~ hp     6     1 hp      -0.0440   1.22e- 1  -3.61e- 1   7.52e- 1  0.0613
#> 19 mpg ~ hp     8     0 (Inte…  18.1      2.99e+ 0   6.05e+ 0   5.74e- 5  0.0804
#> 20 mpg ~ hp     8     0 hp      -0.0142   1.39e- 2  -1.02e+ 0   3.26e- 1  0.0804
#> # … with 11 more variables: adj.r.squared <dbl>, sigma <dbl>,
#> #   model.statistic <dbl>, model.p.value <dbl>, df <dbl>, logLik <dbl>,
#> #   AIC <dbl>, BIC <dbl>, deviance <dbl>, df.residual <int>, nobs <int>, and
#> #   abbreviated variable name ¹​r.squared
cross_fit(mtcars, list(mpg ~ wt, mpg ~ hp), dplyr::starts_with("c"))
#> # A tibble: 36 × 20
#>    model      cyl  carb term   estim…¹ std.e…² stati…³   p.value r.squ…⁴ adj.r…⁵
#>    <chr>    <dbl> <dbl> <chr>    <dbl>   <dbl>   <dbl>     <dbl>   <dbl>   <dbl>
#>  1 mpg ~ wt     4     1 (Inte…   62.0    17.2     3.60   3.67e-2   0.574   0.432
#>  2 mpg ~ wt     4     1 wt      -16.0     7.95   -2.01   1.38e-1   0.574   0.432
#>  3 mpg ~ wt     4     2 (Inte…   36.8     2.83   13.0    2.01e-4   0.802   0.752
#>  4 mpg ~ wt     4     2 wt       -4.56    1.13   -4.02   1.59e-2   0.802   0.752
#>  5 mpg ~ wt     6     1 (Inte…   64.7   NaN     NaN    NaN         1     NaN    
#>  6 mpg ~ wt     6     1 wt      -13.5   NaN     NaN    NaN         1     NaN    
#>  7 mpg ~ wt     6     4 (Inte…   30.2     3.61    8.37   1.40e-2   0.810   0.714
#>  8 mpg ~ wt     6     4 wt       -3.38    1.16   -2.92   1.00e-1   0.810   0.714
#>  9 mpg ~ wt     6     6 (Inte…   19.7   NaN     NaN    NaN         0       0    
#> 10 mpg ~ wt     6     6 wt       NA      NA      NA     NA         0       0    
#> # … with 26 more rows, 10 more variables: sigma <dbl>, model.statistic <dbl>,
#> #   model.p.value <dbl>, df <dbl>, logLik <dbl>, AIC <dbl>, BIC <dbl>,
#> #   deviance <dbl>, df.residual <int>, nobs <int>, and abbreviated variable
#> #   names ¹​estimate, ²​std.error, ³​statistic, ⁴​r.squared, ⁵​adj.r.squared

cross_fit(mtcars, list(hp = mpg ~ hp), cyl, weights = wt)
#> # A tibble: 6 × 20
#>   model weights   cyl term     estimate std.e…¹ stati…² p.value r.squ…³ adj.r.…⁴
#>   <chr> <chr>   <dbl> <chr>       <dbl>   <dbl>   <dbl>   <dbl>   <dbl>    <dbl>
#> 1 hp    wt          4 (Interc… 36.2      5.14     7.03  6.10e-5  0.316   0.240  
#> 2 hp    wt          4 hp       -0.123    0.0601  -2.04  7.17e-2  0.316   0.240  
#> 3 hp    wt          6 (Interc… 20.4      3.49     5.85  2.07e-3  0.0107 -0.187  
#> 4 hp    wt          6 hp       -0.00657  0.0283  -0.232 8.26e-1  0.0107 -0.187  
#> 5 hp    wt          8 (Interc… 18.0      3.36     5.36  1.72e-4  0.0724 -0.00491
#> 6 hp    wt          8 hp       -0.0151   0.0156  -0.968 3.52e-1  0.0724 -0.00491
#> # … with 10 more variables: sigma <dbl>, model.statistic <dbl>,
#> #   model.p.value <dbl>, df <dbl>, logLik <dbl>, AIC <dbl>, BIC <dbl>,
#> #   deviance <dbl>, df.residual <int>, nobs <int>, and abbreviated variable
#> #   names ¹​std.error, ²​statistic, ³​r.squared, ⁴​adj.r.squared
cross_fit(mtcars, list(hp = mpg ~ hp), cyl, weights = c(wt, NA))
#> # A tibble: 12 × 20
#>    model weights   cyl term    estimate std.e…¹ stati…² p.value r.squ…³ adj.r.…⁴
#>    <chr> <chr>   <dbl> <chr>      <dbl>   <dbl>   <dbl>   <dbl>   <dbl>    <dbl>
#>  1 hp    NA          4 (Inter… 36.0      5.20     6.92  6.93e-5  0.274   0.193  
#>  2 hp    NA          4 hp      -0.113    0.0612  -1.84  9.84e-2  0.274   0.193  
#>  3 hp    NA          6 (Inter… 20.7      3.30     6.26  1.53e-3  0.0161 -0.181  
#>  4 hp    NA          6 hp      -0.00761  0.0266  -0.286 7.86e-1  0.0161 -0.181  
#>  5 hp    NA          8 (Inter… 18.1      2.99     6.05  5.74e-5  0.0804  0.00382
#>  6 hp    NA          8 hp      -0.0142   0.0139  -1.02  3.26e-1  0.0804  0.00382
#>  7 hp    wt          4 (Inter… 36.2      5.14     7.03  6.10e-5  0.316   0.240  
#>  8 hp    wt          4 hp      -0.123    0.0601  -2.04  7.17e-2  0.316   0.240  
#>  9 hp    wt          6 (Inter… 20.4      3.49     5.85  2.07e-3  0.0107 -0.187  
#> 10 hp    wt          6 hp      -0.00657  0.0283  -0.232 8.26e-1  0.0107 -0.187  
#> 11 hp    wt          8 (Inter… 18.0      3.36     5.36  1.72e-4  0.0724 -0.00491
#> 12 hp    wt          8 hp      -0.0151   0.0156  -0.968 3.52e-1  0.0724 -0.00491
#> # … with 10 more variables: sigma <dbl>, model.statistic <dbl>,
#> #   model.p.value <dbl>, df <dbl>, logLik <dbl>, AIC <dbl>, BIC <dbl>,
#> #   deviance <dbl>, df.residual <int>, nobs <int>, and abbreviated variable
#> #   names ¹​std.error, ²​statistic, ³​r.squared, ⁴​adj.r.squared

cross_fit(
  mtcars, list(vs ~ cyl, vs ~ hp), am,
  fn = glm, fn_args = list(family = binomial(link = logit))
)
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> Warning: glm.fit: algorithm did not converge
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> # A tibble: 8 × 15
#>   model     am term  estimate std.e…¹ statis…² p.value null.…³ df.null    logLik
#>   <chr>  <dbl> <chr>    <dbl>   <dbl>    <dbl>   <dbl>   <dbl>   <int>     <dbl>
#> 1 vs ~ …     0 (Int… 172.     2.52e+5  6.82e-4   0.999    25.0      18 -2.89e-10
#> 2 vs ~ …     0 cyl   -24.6    3.57e+4 -6.89e-4   0.999    25.0      18 -2.89e-10
#> 3 vs ~ …     1 (Int…  44.3    1.04e+4  4.24e-3   0.997    17.9      12 -3.01e+ 0
#> 4 vs ~ …     1 cyl   -10.6    2.61e+3 -4.06e-3   0.997    17.9      12 -3.01e+ 0
#> 5 vs ~ …     0 (Int… 231.     2.76e+5  8.35e-4   0.999    25.0      18 -5.08e-10
#> 6 vs ~ …     0 hp     -1.69   2.00e+3 -8.44e-4   0.999    25.0      18 -5.08e-10
#> 7 vs ~ …     1 (Int…   7.07   4.76e+0  1.49e+0   0.137    17.9      12 -4.79e+ 0
#> 8 vs ~ …     1 hp     -0.0663 4.67e-2 -1.42e+0   0.156    17.9      12 -4.79e+ 0
#> # … with 5 more variables: AIC <dbl>, BIC <dbl>, deviance <dbl>,
#> #   df.residual <int>, nobs <int>, and abbreviated variable names ¹​std.error,
#> #   ²​statistic, ³​null.deviance
cross_fit(
  mtcars, list(vs ~ cyl, vs ~ hp), am,
  fn = ~ glm(.x, .y, family = binomial(link = logit))
)
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> Warning: glm.fit: algorithm did not converge
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
#> # A tibble: 8 × 15
#>   model     am term  estimate std.e…¹ statis…² p.value null.…³ df.null    logLik
#>   <chr>  <dbl> <chr>    <dbl>   <dbl>    <dbl>   <dbl>   <dbl>   <int>     <dbl>
#> 1 vs ~ …     0 (Int… 172.     2.52e+5  6.82e-4   0.999    25.0      18 -2.89e-10
#> 2 vs ~ …     0 cyl   -24.6    3.57e+4 -6.89e-4   0.999    25.0      18 -2.89e-10
#> 3 vs ~ …     1 (Int…  44.3    1.04e+4  4.24e-3   0.997    17.9      12 -3.01e+ 0
#> 4 vs ~ …     1 cyl   -10.6    2.61e+3 -4.06e-3   0.997    17.9      12 -3.01e+ 0
#> 5 vs ~ …     0 (Int… 231.     2.76e+5  8.35e-4   0.999    25.0      18 -5.08e-10
#> 6 vs ~ …     0 hp     -1.69   2.00e+3 -8.44e-4   0.999    25.0      18 -5.08e-10
#> 7 vs ~ …     1 (Int…   7.07   4.76e+0  1.49e+0   0.137    17.9      12 -4.79e+ 0
#> 8 vs ~ …     1 hp     -0.0663 4.67e-2 -1.42e+0   0.156    17.9      12 -4.79e+ 0
#> # … with 5 more variables: AIC <dbl>, BIC <dbl>, deviance <dbl>,
#> #   df.residual <int>, nobs <int>, and abbreviated variable names ¹​std.error,
#> #   ²​statistic, ³​null.deviance

cross_fit(mtcars, list(mpg ~ wt, mpg ~ hp), cyl, tidy = FALSE)
#> # A tibble: 6 × 3
#>   model      cyl fit   
#>   <chr>    <dbl> <list>
#> 1 mpg ~ wt     4 <lm>  
#> 2 mpg ~ wt     6 <lm>  
#> 3 mpg ~ wt     8 <lm>  
#> 4 mpg ~ hp     4 <lm>  
#> 5 mpg ~ hp     6 <lm>  
#> 6 mpg ~ hp     8 <lm>  
cross_fit(mtcars, list(mpg ~ wt, mpg ~ hp), cyl, tidy_args = c(conf.int = TRUE))
#> # A tibble: 12 × 21
#>    model      cyl term  estimate std.e…¹ stati…² p.value conf.…³ conf.…⁴ r.squ…⁵
#>    <chr>    <dbl> <chr>    <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>
#>  1 mpg ~ wt     4 (Int… 39.6      4.35     9.10  7.77e-6 29.7    49.4     0.509 
#>  2 mpg ~ wt     4 wt    -5.65     1.85    -3.05  1.37e-2 -9.83   -1.46    0.509 
#>  3 mpg ~ wt     6 (Int… 28.4      4.18     6.79  1.05e-3 17.7    39.2     0.465 
#>  4 mpg ~ wt     6 wt    -2.78     1.33    -2.08  9.18e-2 -6.21    0.651   0.465 
#>  5 mpg ~ wt     8 (Int… 23.9      3.01     7.94  4.05e-6 17.3    30.4     0.423 
#>  6 mpg ~ wt     8 wt    -2.19     0.739   -2.97  1.18e-2 -3.80   -0.582   0.423 
#>  7 mpg ~ hp     4 (Int… 36.0      5.20     6.92  6.93e-5 24.2    47.7     0.274 
#>  8 mpg ~ hp     4 hp    -0.113    0.0612  -1.84  9.84e-2 -0.251   0.0256  0.274 
#>  9 mpg ~ hp     6 (Int… 20.7      3.30     6.26  1.53e-3 12.2    29.2     0.0161
#> 10 mpg ~ hp     6 hp    -0.00761  0.0266  -0.286 7.86e-1 -0.0759  0.0607  0.0161
#> 11 mpg ~ hp     8 (Int… 18.1      2.99     6.05  5.74e-5 11.6    24.6     0.0804
#> 12 mpg ~ hp     8 hp    -0.0142   0.0139  -1.02  3.26e-1 -0.0445  0.0160  0.0804
#> # … with 11 more variables: adj.r.squared <dbl>, sigma <dbl>,
#> #   model.statistic <dbl>, model.p.value <dbl>, df <dbl>, logLik <dbl>,
#> #   AIC <dbl>, BIC <dbl>, deviance <dbl>, df.residual <int>, nobs <int>, and
#> #   abbreviated variable names ¹​std.error, ²​statistic, ³​conf.low, ⁴​conf.high,
#> #   ⁵​r.squared

cross_fit(mtcars, list(mpg ~ wt, mpg ~ hp), cyl, tidy = broom::tidy)
#> # A tibble: 12 × 7
#>    model      cyl term        estimate std.error statistic    p.value
#>    <chr>    <dbl> <chr>          <dbl>     <dbl>     <dbl>      <dbl>
#>  1 mpg ~ wt     4 (Intercept) 39.6        4.35       9.10  0.00000777
#>  2 mpg ~ wt     4 wt          -5.65       1.85      -3.05  0.0137    
#>  3 mpg ~ wt     6 (Intercept) 28.4        4.18       6.79  0.00105   
#>  4 mpg ~ wt     6 wt          -2.78       1.33      -2.08  0.0918    
#>  5 mpg ~ wt     8 (Intercept) 23.9        3.01       7.94  0.00000405
#>  6 mpg ~ wt     8 wt          -2.19       0.739     -2.97  0.0118    
#>  7 mpg ~ hp     4 (Intercept) 36.0        5.20       6.92  0.0000693 
#>  8 mpg ~ hp     4 hp          -0.113      0.0612    -1.84  0.0984    
#>  9 mpg ~ hp     6 (Intercept) 20.7        3.30       6.26  0.00153   
#> 10 mpg ~ hp     6 hp          -0.00761    0.0266    -0.286 0.786     
#> 11 mpg ~ hp     8 (Intercept) 18.1        2.99       6.05  0.0000574 
#> 12 mpg ~ hp     8 hp          -0.0142     0.0139    -1.02  0.326     
cross_fit(
  mtcars, list(mpg ~ wt, mpg ~ hp), cyl,
  tidy = ~ broom::tidy(., conf.int = TRUE)
)
#> # A tibble: 12 × 9
#>    model      cyl term        estimate std.error stati…¹ p.value conf.…² conf.…³
#>    <chr>    <dbl> <chr>          <dbl>     <dbl>   <dbl>   <dbl>   <dbl>   <dbl>
#>  1 mpg ~ wt     4 (Intercept) 39.6        4.35     9.10  7.77e-6 29.7    49.4   
#>  2 mpg ~ wt     4 wt          -5.65       1.85    -3.05  1.37e-2 -9.83   -1.46  
#>  3 mpg ~ wt     6 (Intercept) 28.4        4.18     6.79  1.05e-3 17.7    39.2   
#>  4 mpg ~ wt     6 wt          -2.78       1.33    -2.08  9.18e-2 -6.21    0.651 
#>  5 mpg ~ wt     8 (Intercept) 23.9        3.01     7.94  4.05e-6 17.3    30.4   
#>  6 mpg ~ wt     8 wt          -2.19       0.739   -2.97  1.18e-2 -3.80   -0.582 
#>  7 mpg ~ hp     4 (Intercept) 36.0        5.20     6.92  6.93e-5 24.2    47.7   
#>  8 mpg ~ hp     4 hp          -0.113      0.0612  -1.84  9.84e-2 -0.251   0.0256
#>  9 mpg ~ hp     6 (Intercept) 20.7        3.30     6.26  1.53e-3 12.2    29.2   
#> 10 mpg ~ hp     6 hp          -0.00761    0.0266  -0.286 7.86e-1 -0.0759  0.0607
#> 11 mpg ~ hp     8 (Intercept) 18.1        2.99     6.05  5.74e-5 11.6    24.6   
#> 12 mpg ~ hp     8 hp          -0.0142     0.0139  -1.02  3.26e-1 -0.0445  0.0160
#> # … with abbreviated variable names ¹​statistic, ²​conf.low, ³​conf.high