| cv_buffer | R Documentation |
This function generates spatially separated train and test folds by considering buffers of
the specified distance (size parameter) around each observation point.
This approach is a form of leave-one-out cross-validation. Each fold is generated by excluding
nearby observations around each testing point within the specified distance (ideally the range of
spatial autocorrelation in model residuals, see cv_spatial_autocor). In this method, the testing set never
directly abuts a training sample (e.g. presence or absence; 0s and 1s). For more information see the details section.
cv_buffer(
x,
column = NULL,
size,
presence_bg = FALSE,
add_bg = FALSE,
num_bins = 4L,
report = interactive(),
progress = interactive()
)
x |
a simple features (sf) or SpatialPoints object of spatial sample data (e.g., species data or ground truth sample for image classification). |
column |
character; indicating the name of the column in which response variable (e.g. species data as a binary
response i.e. 0s and 1s) is stored. This is required when |
size |
numeric value of the specified range by which training/testing data are separated.
This distance should be in metres. The range could be explored by |
presence_bg |
logical; whether to treat data as species presence-background data. For all other data
types (presence-absence, continuous, count or multi-class responses), this option should be |
add_bg |
logical; add background points to the test set when |
num_bins |
integer; the number of quantile bins used to stratify a continuous numeric |
report |
logical; whether to print summary of records in each fold.
Defaults to |
progress |
logical; whether to shows a progress bar. Defaults to |
In presence-background data the response column holds 1 for recorded presences and
0 for background (or “pseudo-absence”) points – locations sampled across the study
area to characterise the available conditions rather than confirmed absences. This framing is common in
species distribution modelling, but the option suits any presence-only-style data (e.g. sightings,
occurrences or detections without reliable absences). When working with such data (specified by
presence_bg = TRUE), only presence records are used for specifying the folds (recommended). Consider a target presence point. The buffer is defined around this target point,
using the specified range (size). By default, the testing fold comprises only the target presence point (all background
points within the buffer are also added when add_bg = TRUE).
Any non-target presence points inside the buffer are excluded.
All points (presence and background) outside of buffer are used for the training set.
The methods cycles through all the presence data, so the number of folds is equal to
the number of presence points in the dataset.
For presence-absence data (and all other types of data), folds are created based on all records, both
presences and absences. As above, a target observation (presence or absence) forms a test point, all
presence and absence points other than the target point within the buffer are ignored, and the training
set comprises all presences and absences outside the buffer. Apart from the folds, the number
of training-presence, training-absence, testing-presence and testing-absence
records is stored and returned in the records table. If column = NULL and presence_bg = FALSE,
the procedure is like presence-absence data. All other data types (continuous, count or multi-class responses) should be
done by presence_bg = FALSE.
An object of class S3. A list of objects including:
folds_list - a list containing the folds. Each fold has two vectors with the training (first) and testing (second) indices
k - number of the folds
size - the defined range of spatial autocorrelation)
column - the name of the column if provided
presence_bg - whether this was treated as presence-background data
records - a table with the number of points in each category of training and testing
Valavi, R., Elith, J., Lahoz-Monfort, J. J., & Guillera-Arroita, G. (2019). blockCV: An R package for generating spatially or environmentally separated folds for k-fold cross-validation of species distribution models. Methods in Ecology and Evolution, 10(2), 225-232. doi:10.1111/2041-210X.13107.
Radosavljevic, A., & Anderson, R. P. (2014). Making better Maxent models of species distributions: Complexity, overfitting and evaluation. Journal of Biogeography, 41, 629–643. https://doi.org/10.1111/jbi.12227
cv_nndm, cv_spatial, and cv_spatial_autocor;
cv_plot to visualise, and cv_distance and cv_similarity to evaluate, the folds
library(blockCV)
# import presence-absence species data
points <- read.csv(system.file("extdata/", "species.csv", package = "blockCV"))
# make an sf object from data.frame
pa_data <- sf::st_as_sf(points, coords = c("x", "y"), crs = 7845)
bloo <- cv_buffer(x = pa_data,
column = "occ",
size = 350000, # size in metres no matter the CRS
presence_bg = FALSE)
# presence-background data
points_pb <- read.csv(system.file("extdata/", "species_pb.csv", package = "blockCV"))
pb_data <- sf::st_as_sf(points_pb, coords = c("x", "y"), crs = 7845)
bloo_pb <- cv_buffer(x = pb_data,
column = "occ",
size = 350000,
presence_bg = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.