cross_fit | R Documentation |
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") )
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 |
cols |
Columns to subset the data.
Can be any expression supported by
< |
weights |
A list of columns passed to |
clusters |
A list of columns passed to |
families |
A list of glm model families passed to |
fn |
The modeling function.
Either an unquoted function name or a purrr-style lambda
function with two arguments.
To use multiple modeling functions, see |
fn_args |
A list of additional arguments to |
tidy |
A logical or function to use to tidy model output into
data.frame columns.
If |
tidy_args |
A list of additional arguments to the |
errors |
If |
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
)
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.
cross_fit(mtcars, mpg ~ wt, cyl) cross_fit(mtcars, list(mpg ~ wt, mpg ~ hp), cyl) cross_fit(mtcars, list(wt = mpg ~ wt, hp = mpg ~ hp), cyl) cross_fit(mtcars, list(mpg ~ wt, mpg ~ hp), c(cyl, vs)) cross_fit(mtcars, list(mpg ~ wt, mpg ~ hp), dplyr::starts_with("c")) cross_fit(mtcars, list(hp = mpg ~ hp), cyl, weights = wt) cross_fit(mtcars, list(hp = mpg ~ hp), cyl, weights = c(wt, NA)) cross_fit( mtcars, list(vs ~ cyl, vs ~ hp), am, fn = glm, fn_args = list(family = binomial(link = logit)) ) cross_fit( mtcars, list(vs ~ cyl, vs ~ hp), am, fn = ~ glm(.x, .y, family = binomial(link = logit)) ) cross_fit(mtcars, list(mpg ~ wt, mpg ~ hp), cyl, tidy = FALSE) cross_fit(mtcars, list(mpg ~ wt, mpg ~ hp), cyl, tidy_args = c(conf.int = TRUE)) cross_fit(mtcars, list(mpg ~ wt, mpg ~ hp), cyl, tidy = broom::tidy) cross_fit( mtcars, list(mpg ~ wt, mpg ~ hp), cyl, tidy = ~ broom::tidy(., conf.int = TRUE) )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.