generate_cv_folds {glossa} | R Documentation |
Generate cross-validation folds
Description
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.
Usage
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")
)
Arguments
data |
A 'data.frame' with at least presence-absence data ('pa'), coordinates, and optionally a 'timestamp'. |
method |
The cross-validation strategy. One of: '"k-fold"', '"spatial_blocks"', '"temporal_blocks"'. |
block_method |
For spatial blocks, how to determine block size. One of: '"residuals_autocorrelation"', '"predictors_autocorrelation"', '"manual"'. |
block_size |
Numeric. Manual block size in meters (used if 'block_method = "manual"'). |
k |
Integer. Number of folds to generate. |
predictor_raster |
A 'terra::SpatRaster' used for estimating spatial autocorrelation (only needed if 'block_method = "predictors_autocorrelation"'). |
model_residuals |
A 'data.frame' with residuals and coordinates (only needed if 'block_method = "residuals_autocorrelation"'). |
coords |
A character vector of length 2 indicating the longitude and latitude column names. |
Value
A list with the following elements:
- folds
A vector of fold assignments (one per row in 'data').
- method
The CV method used.
- block_method
The spatial block size method (if applicable).
- block_size
The estimated or manual block size (in meters), if spatial blocks were used.