Create a spatial-aware cross-validation split for H3 data
Source:R/h3sdm_spatial_cv.R
h3sdm_spatial_cv.RdGenerates a spatially aware cross-validation split for species distribution modeling using H3 hexagonal grids. This helps avoid inflated model performance estimates caused by spatial autocorrelation, producing more robust model evaluation.
Arguments
- data
An
sfobject, typically the output ofh3sdm_data().- method
Character. The spatial resampling method to use:
- "block"
Use
spatialsample::spatial_block_cv()for block-based spatial CV.- "cluster"
Use
spatialsample::spatial_clustering_cv()for cluster-based spatial CV.
- v
Integer. Number of folds (default = 5).
- ...
Additional arguments passed to the underlying
spatialsamplefunction.
Details
Spatial cross-validation avoids overly optimistic performance estimates by ensuring that training and testing data are spatially separated.
"block": Divides the spatial domain into contiguous blocks."cluster": Groups locations into spatial clusters before splitting.
Examples
if (FALSE) { # \dontrun{
# Example: Create spatial cross-validation splits for H3 data
# Block spatial CV with default folds
spatial_cv_block <- h3sdm_spatial_cv(combined_data, method = "block")
# Cluster spatial CV with 10 folds
spatial_cv_cluster <- h3sdm_spatial_cv(combined_data, method = "cluster", v = 10)
} # }