Create multiple tidymodels workflows for H3-based SDMs
Source:R/h3sdm_workflows.R
h3sdm_workflows.RdCreates a list of tidymodels workflows from multiple model specifications and a prepared recipe. This is useful for comparing different modeling approaches in species distribution modeling using H3 hexagonal grids.
Arguments
- model_specs
A named list of
tidymodelsmodel specifications (e.g.,logistic_reg(),rand_forest(),boost_tree()), where each element specifies a different modeling approach. All specifications must use the same mode:set_mode("classification")for presence/absence models orset_mode("regression")for count-based models.- recipe
A
tidymodelsrecipe object, typically created withh3sdm_recipe(), which prepares and preprocesses the data for modeling. Useresponse_col = "count"inh3sdm_recipe()when working with count data.
Details
This function automates the creation of workflows for multiple model specifications. Each workflow combines the same preprocessing steps (recipe) with a different modeling method, facilitating systematic comparison of models.
Choosing the model mode:
For presence/absence data: use
set_mode("classification")for all model specifications.For count data (species richness, detections, individuals): use
set_mode("regression")for all model specifications.
Examples
if (FALSE) { # \dontrun{
library(parsnip)
# --- Presence/absence models ---
specs_pa <- list(
rf = rand_forest() %>% set_engine("ranger") %>% set_mode("classification"),
glm = logistic_reg() %>% set_engine("glm") %>% set_mode("classification")
)
rec_pa <- h3sdm_recipe(combined_data)
wfs_pa <- h3sdm_workflows(model_specs = specs_pa, recipe = rec_pa)
# --- Count-based models ---
specs_count <- list(
rf = rand_forest() %>% set_engine("ranger") %>% set_mode("regression"),
xgb = boost_tree() %>% set_engine("xgboost") %>% set_mode("regression")
)
rec_count <- h3sdm_recipe(combined_data, response_col = "count")
wfs_count <- h3sdm_workflows(model_specs = specs_count, recipe = rec_count)
} # }