Generate presence/pseudo-absence dataset stratified in environmental space
Source:R/h3sdm_pa.R
h3sdm_pa.RdCombines presence hexagons with pseudo-absences sampled in environmental space. Pseudo-absences are selected by clustering the environmental conditions of hexagons without presence records using k-means, then choosing the hexagon closest to each cluster centroid. This ensures pseudo-absences cover the full range of environmental conditions available in the AOI, reducing bias from spatially clustered occurrence records.
Arguments
- pres_sf
sfPresence hexagons returned byh3sdm_pres().- predictors_sf
sfFull hexagonal grid with extracted environmental variables, returned byh3sdm_predictors().- n_pseudoabs
integerNumber of pseudo-absence hexagons to sample. If larger than the number of available hexagons without presence, all available hexagons are used. Default is500.- buffer_k
integerNumber of H3 grid rings to exclude around each presence hexagon when building the pseudo-absence candidate pool. Hexagons withinbuffer_krings of any presence are removed before sampling, preventing pseudo-absences from being placed in areas likely occupied but not yet recorded. Default is1. Set to0to disable.
Value
sf object with columns:
h3_address: H3 index of the hexagon.presence: factor with levels"0"(pseudo-absence) and"1"(presence).geometry: MULTIPOLYGON of each hexagon.
Details
The function scales all numeric predictor columns before clustering. Non-numeric columns and columns with zero variance are excluded from clustering. Pseudo-absences are selected as the hexagon nearest to each k-means centroid in scaled environmental space (Euclidean distance).
This function is designed to be used after h3sdm_pres() and
h3sdm_predictors() in the following workflow:
pres <- h3sdm_pres("Species name", aoi_sf, res = 7)
num_vars <- h3sdm_extract_num(raster_stack, grid)
predictors <- h3sdm_predictors(num_vars)
pa <- h3sdm_pa(pres, predictors, n_pseudoabs = 500)Examples
if (FALSE) { # \dontrun{
data(cr_outline_c, package = "h3sdm")
pres <- h3sdm_pres("Agalychnis callidryas", cr_outline_c, res = 7)
grid <- h3sdm_get_grid(cr_outline_c, res = 7)
num_vars <- h3sdm_extract_num(bio, grid)
predictors <- h3sdm_predictors(num_vars)
pa <- h3sdm_pa(pres, predictors, n_pseudoabs = 300)
} # }