Cross fit robust linear models
A data frame
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.
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
.
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
.
A list of columns passed to clusters
.
If one of the elements is NULL
or NA
, that model will not
be clustered.
Defaults to NULL
.
A list of additional arguments to estimatr::lm_robust()
.
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.
A list of additional arguments to the tidy
function
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.
A tibble with a column for the model formula,
columns for subsets,
columns for the weights and clusters (if applicable),
and columns of tidy model output or a list column of models
(if tidy = FALSE
)
cross_fit()
to use any modeling function.
cross_fit_robust(mtcars, mpg ~ wt, cyl, clusters = list(NULL, am))
#> # A tibble: 12 × 19
#> model clusters cyl term estim…¹ std.e…² stati…³ p.value conf.…⁴ conf.…⁵
#> <chr> <chr> <dbl> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 mpg ~ wt NULL 4 (Int… 39.6 3.20 12.4 5.95e-7 32.3 46.8
#> 2 mpg ~ wt NULL 4 wt -5.65 1.37 -4.12 2.59e-3 -8.75 -2.55
#> 3 mpg ~ wt NULL 6 (Int… 28.4 2.82 10.1 1.66e-4 21.2 35.7
#> 4 mpg ~ wt NULL 6 wt -2.78 0.934 -2.98 3.09e-2 -5.18 -0.380
#> 5 mpg ~ wt NULL 8 (Int… 23.9 3.19 7.48 7.45e-6 16.9 30.8
#> 6 mpg ~ wt NULL 8 wt -2.19 0.825 -2.66 2.09e-2 -3.99 -0.394
#> 7 mpg ~ wt am 4 (Int… 39.6 6.59 6.00 6.11e-2 -6.45 85.6
#> 8 mpg ~ wt am 4 wt -5.65 2.55 -2.21 2.19e-1 -24.3 13.1
#> 9 mpg ~ wt am 6 (Int… 28.4 6.54 4.35 6.75e-2 -5.94 62.8
#> 10 mpg ~ wt am 6 wt -2.78 1.94 -1.43 3.01e-1 -12.1 6.55
#> 11 mpg ~ wt am 8 (Int… 23.9 1.94 12.3 4.13e-2 3.83 43.9
#> 12 mpg ~ wt am 8 wt -2.19 0.391 -5.60 9.61e-2 -6.19 1.81
#> # … with 9 more variables: df <dbl>, outcome <chr>, r.squared <dbl>,
#> # adj.r.squared <dbl>, model.statistic <dbl>, model.p.value <dbl>,
#> # df.residual <dbl>, nobs <int>, se_type <chr>, and abbreviated variable
#> # names ¹estimate, ²std.error, ³statistic, ⁴conf.low, ⁵conf.high