Skip to contents

Each group (a region, a population, a lineage, a cytotype, a survey) is held out in turn, or groups are combined into k folds of similar size. This tests transfer between biological or geographic units, the question behind most projections to other regions or to related taxa, rather than interpolation between nearby points (Roberts et al. 2017).

Usage

group_folds(groups, k = NULL)

Arguments

groups

Group of each point (vector).

k

Optional number of folds. NULL (default): one fold per group. Otherwise groups are assigned to k folds, largest first, each to the fold with the fewest points so far.

Value

An integer vector of folds, with attribute groups (the group of each fold).

Details

Status and limits. An established design (leave-one-group-out; Roberts et al. 2017). Groups of very different size give folds of very different size; with few groups each fold is a single unit, and the metrics vary with that unit. What to vary. The grouping (e.g. regions against lineages) and k.

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

group_folds(c("north", "north", "south", "east", "south"))
#> [1] 1 1 2 3 2
#> attr(,"groups")
#> [1] "north" "south" "east" 
group_folds(rep(letters[1:6], times = 6:1), k = 3)
#>  [1] 1 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 3 3 2 2 1
#> attr(,"groups")
#> [1] "a, f" "b, e" "c, d"