
Training points to exclude around each test fold (buffered CV)
Source:R/cv_designs.R
buffer_exclusion.RdSpatial blocks keep test points away from most training points, but
points on either side of a block boundary are still neighbours. Buffered
cross-validation removes from the training data every point within
buffer_km of a test point, so the model is always tested at least that
far from its training data (Roberts et al. 2017). buffer_exclusion()
gives, for each fold, which points to drop from training; fit each model
without them.
Usage
buffer_exclusion(
points,
fold,
buffer_km,
coords = NULL,
points_crs = "EPSG:4326",
crs = NULL
)Value
A logical matrix with one row per point and one column per fold:
TRUE = drop the point from training when that fold is the test fold.
Points of the test fold itself are FALSE (they are not training
points). Attribute share_dropped: the share of training points
dropped for each fold.
Details
Status and limits. An established design (buffered or spatially
separated CV; Roberts et al. 2017). Large buffers remove much of the
training data, especially around big folds; the printed share says how
much. What to vary. buffer_km, e.g. from suggest_block_size().
References
Roberts, D.R., Bahn, V., Ciuti, S., et al. (2017) Cross-validation strategies for data with temporal, spatial, hierarchical, or phylogenetic structure. Ecography 40, 913-929. doi:10.1111/ecog.02881
Examples
pts <- data.frame(lon = c(10, 10.05, 10.5, 11, 12), lat = 50)
ex <- buffer_exclusion(pts, fold = c(1, 2, 2, 1, 2), buffer_km = 10)
ex
#> fold_1 fold_2
#> [1,] FALSE TRUE
#> [2,] TRUE FALSE
#> [3,] FALSE FALSE
#> [4,] FALSE FALSE
#> [5,] FALSE FALSE
#> attr(,"share_dropped")
#> fold_1 fold_2
#> 0.3333333 0.5000000
# training data for fold 1: points not in fold 1 and not excluded
which(c(1, 2, 2, 1, 2) != 1 & !ex[, 1])
#> [1] 3 5