Skip to content

Prepares an sf object with H3 hexagonal data for modeling with the tidymodels ecosystem. Extracts centroid coordinates, assigns appropriate roles to the variables automatically, and returns a ready-to-use recipe for modeling species distributions.

Usage

h3sdm_recipe(data, response_col = "presence")

Arguments

data

An sf object, typically the output of h3sdm_data(), including species presence-absence or count data, H3 addresses, and environmental predictors. The geometry must be of type MULTIPOLYGON.

response_col

character Name of the column to use as the outcome (response variable). Default "presence" for presence/absence models. Use "count" when working with count data generated by h3sdm_count_from_records().

Value

A tidymodels recipe object (class "h3sdm_recipe") ready for modeling.

Details

This function prepares spatial H3 grid data for species distribution modeling:

  • Extracts centroid coordinates (x and y) from MULTIPOLYGON geometries.

  • Removes the geometry column to create a purely tabular dataset for tidymodels.

  • Assigns roles to columns:

    • response_col"outcome" (target variable)

    • h3_address"id" (used for joining predictions later)

    • x and y"spatial_predictor"

  • All other columns are assigned "predictor" role.

Examples

if (FALSE) { # \dontrun{
# Presence/absence model (default)
sdm_recipe <- h3sdm_recipe(combined_data)

# Count-based model
sdm_recipe <- h3sdm_recipe(combined_data, response_col = "count")
} # }