map_models | R Documentation |
Use when creating multiple models which vary by one parameter. See example below.
map_models( df, params, model_str, engine = parsnip::set_engine(object = parsnip::logistic_reg(), engine = "glm"), rm_raw_model = TRUE )
df |
Data frame. |
params |
A character vector of values to substitute |
model_str |
A model formula as a string, containing one variable as |
engine |
A |
rm_raw_model |
If |
Ideally aim to supply a df
without missing data. Otherwise, check N
observations for models (in fit
column, model_glance
) to see if many (or
any) observations were removed.
A data frame
# dummy dataset mtcars2 <- mtcars %>% tibble::rownames_to_column(var = "make") %>% dplyr::mutate("is_merc" = ifelse(stringr::str_detect(.data[["make"]], pattern = "^Merc"), yes = 1, no = 0 )) %>% tibble::as_tibble() %>% dplyr::mutate(dplyr::across(tidyselect::starts_with("is_"), as.factor)) # preview dummy dataset mtcars2 # run `map_models()` - logistic regression to predict Mercedes make result <- map_models( df = mtcars2, model_str = "is_merc ~ mpg + cyl + disp + {.x}", params = c(GEAR = 'gear', CARB = 'carb'), engine = parsnip::set_engine(object = parsnip::logistic_reg(), engine = "glm"), rm_raw_model = FALSE ) # view result result # model outputs are stored in the `fit` column names(result$fit[[1]]) # 'tidy' model outputs are under `model_tidy` result$fit[[1]]$model_tidy # 'glance' model outputs are under `model_glance` result$fit[[1]]$model_glance # `model_raw` contains either the raw model under `result`, or an error message under `error` names(result$fit[[1]]$model_raw)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.