Skip to content

Trains a single tidymodels workflow using a spatial split, computes performance metrics for each fold, and fits the final model to the full dataset. Optionally computes post-hoc metrics like TSS and the Boyce index.

Usage

h3sdm_fit_model(
  sdm_workflow,
  data_split,
  presence_data = NULL,
  truth_col = "presence",
  pred_col = ".pred_1"
)

Arguments

sdm_workflow

A workflow object from h3sdm_workflow() or manually created.

data_split

A resampling object (e.g., from vfold_cv() or h3sdm_spatial_cv()) for cross-validation.

presence_data

Optional sf or tibble with presence locations to compute Boyce index.

truth_col

Character. Name of the column containing the true presence/absence values (default "presence").

pred_col

Character. Name of the column containing predicted probabilities (default ".pred_1").

Value

A list with:

cv_model

Results of cross-validation (tune_results).

final_model

Fitted workflow on full data.

metrics

Tibble with performance metrics including ROC AUC, accuracy, sensitivity, specificity, F1-score, Kappa, TSS, and Boyce index.

Examples

if (FALSE) { # \dontrun{
fitted <- h3sdm_fit_model(
  sdm_workflow  = my_workflow,
  data_split    = my_cv,
  presence_data = my_presence_sf
)
} # }