| aoe_sample | R Documentation |
Sample points from an aoe_result with control over core/halo balance.
This is useful when core regions dominate due to point density, and you
want balanced representation for modelling.
aoe_sample(x, ...)
## Default S3 method:
aoe_sample(x, ...)
## S3 method for class 'aoe_result'
aoe_sample(
x,
n = NULL,
ratio = c(core = 0.5, halo = 0.5),
replace = FALSE,
by = c("overall", "support"),
...
)
x |
An |
... |
Additional arguments passed to methods. |
n |
Total number of points to sample. If |
ratio |
Named numeric vector specifying the target proportion of core
and halo points. Must sum to 1. Default is |
replace |
Logical. Sample with replacement? Default is |
by |
Character. Stratification grouping:
|
Fixed n: When n is specified, the function samples exactly n points
(or fewer if not enough available), distributed according to ratio.
Balanced downsampling: When n is NULL, the function downsamples
the larger stratum to match the smaller one according to ratio.
For example, with ratio c(core = 0.5, halo = 0.5) and 100 core + 20 halo
points, it returns 20 core + 20 halo = 40 points.
With by = "support", sampling is done independently within each support,
then results are combined. This ensures each support contributes balanced
samples. With by = "overall", all points are pooled first.
An aoe_result object containing the sampled points, preserving
all original columns and attributes. Has additional attribute
sample_info with details about the sampling.
aoe() for computing AoE classifications
library(sf)
support <- st_as_sf(
data.frame(id = 1),
geometry = st_sfc(st_polygon(list(
cbind(c(0, 100, 100, 0, 0), c(0, 0, 100, 100, 0))
))),
crs = 32631
)
# Many points in core, few in halo
set.seed(42)
pts <- st_as_sf(
data.frame(id = 1:60),
geometry = st_sfc(c(
lapply(1:50, function(i) st_point(c(runif(1, 10, 90), runif(1, 10, 90)))),
lapply(1:10, function(i) st_point(c(runif(1, 110, 140), runif(1, 10, 90))))
)),
crs = 32631
)
result <- aoe(pts, support, scale = 1)
# Balance core/halo (downsamples core to match halo)
balanced <- aoe_sample(result)
# Fixed sample size with 70/30 split
sampled <- aoe_sample(result, n = 20, ratio = c(core = 0.7, halo = 0.3))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.