Creates cross-validation fold assignments for presence-absence or presence-only data, supporting three types of strategies: k-fold, spatial blocks (through blockCV R package), and temporal blocks.
generate_cv_folds(
data,
method = "k-fold",
block_method = "predictors_autocorrelation",
block_size = NULL,
k = 10,
predictor_raster = NULL,
model_residuals = NULL,
coords = c("decimalLongitude", "decimalLatitude")
)
A list with the following elements:
A vector of fold assignments (one per row in `data`).
The CV method used.
The spatial block size method (if applicable).
The estimated or manual block size (in meters), if spatial blocks were used.
A `data.frame` with at least presence-absence data (`pa`), coordinates, and optionally a `timestamp`.
The cross-validation strategy. One of: `"k-fold"`, `"spatial_blocks"`, `"temporal_blocks"`.
For spatial blocks, how to determine block size. One of: `"residuals_autocorrelation"`, `"predictors_autocorrelation"`, `"manual"`.
Numeric. Manual block size in meters (used if `block_method = "manual"`).
Integer. Number of folds to generate.
A `terra::SpatRaster` used for estimating spatial autocorrelation (only needed if `block_method = "predictors_autocorrelation"`).
A `data.frame` with residuals and coordinates (only needed if `block_method = "residuals_autocorrelation"`).
A character vector of length 2 indicating the longitude and latitude column names.