Creates a tidymodels workflow for Generalized Additive Models (GAM).
Source:R/h3sdm_workflow_gam.R
h3sdm_workflow_gam.RdThis function constructs a workflow object by combining a GAM model
specification (gen_additive_mod with the mgcv engine) with either
a recipe object or an explicit model formula.
It is optimized for Species Distribution Models (SDM) that use smooth splines,
ensuring that the specialized GAM formula (containing s() terms) is
correctly passed to the model, even when a recipe is provided for general
data preprocessing.
Arguments
- gam_spec
A
parsnipmodel specification of typegen_additive_mod(), configured withset_engine("mgcv").- recipe
(Optional) A
recipespackagerecipeobject (e.g., the output ofh3sdm_recipe_gam). Used for general data preprocessing like normalization or dummy variable creation.- formula
(Optional) A
formulaobject that defines the structure of the GAM, including smooth terms (e.g.,y ~ s(x1) + s(x, y)). If provided alongsiderecipe, this formula overrides the recipe's implicit formula for the final model fit.
Value
A workflow object, ready for fitting with fit() or
resampling with fit_resamples() or tune_grid().
Details
Formula Priority:
If only
recipeis provided, the workflow uses the recipe's implicit formula (e.g.,outcome ~ .).If
recipeandformulaare provided, the workflow uses therecipefor data preprocessing but explicitly passes theformulato themgcvengine for fitting, enabling the use of specialized terms likes(x, y).
See also
Other h3sdm_tools:
h3sdm_recipe_gam(),
h3sdm_stack_fit()
Examples
if (FALSE) { # \dontrun{
library(parsnip)
# 1. Define the model specification
gam_spec <- gen_additive_mod() %>%
set_engine("mgcv") %>%
set_mode("classification")
# 2. Define a specialized GAM formula
gam_formula <- presence ~ s(bio1) + s(x, y, bs = "tp")
# 3. Define a base recipe (assuming 'data' exists)
# base_rec <- h3sdm_recipe_gam(data)
# 4. Create the combined workflow
# h3sdm_wf <- h3sdm_workflow_gam(
# gam_spec = gam_spec,
# recipe = base_rec,
# formula = gam_formula
# )
} # }