Samples a single spatial point for each polygon based on an underlying spatial weights dataset. An auxiliary vector can be provided to define a secondary sampling unit and limit where points may be sampled.
Usage
wt_strata(x, weights, ...)
# S3 method for class 'SpatVector'
wt_strata(x, weights, ...)
# S3 method for class 'sf'
wt_strata(x, weights, ...)
# S3 method for class 'sfc'
wt_strata(
x,
weights,
...,
psu = NULL,
ssu = NULL,
schema = NULL,
ids = NULL,
reuse_weights = TRUE,
composition = "reductive",
smooth = FALSE,
smooth_opts = list(fun = "mean")
)Arguments
- x
A spatial object containing vector data (
sfc,sf, orSpatVector) and eitherPOLYGON/MULTIPOLYGONgeometries orPOINT/MULTIPOINTgeometries. If polygons are provided, they are interpreted as primary sampling units. If points are provided, polygons must be provided topsuto be linked to the points inxthrough a spatial join. For each row inx, a spatial point representation is estimated based on the reference data inweights.- weights
An object of class
sf,sfc,SpatVector, orSpatRasterthat is used to define spatial weights. For example, this could be a population raster to define weights based on where people live. If raster data is provided, it is masked and vectorized internally. In any case, the polygons are intersected with the outer boundaries ofxsuch that no points can be sampled outside of its boundaries.- ...
Further arguments passed to
wt_sample.- psu
Optional spatial vector dataset of class
sf,sfc, orSpatVectorrepresenting the primary sampling unit (PSU). If not provided (the default),xis required to consist of polygons (which then act as the PSU). PSUs limit where each location inxcan be sampled.- ssu
Optional character vector or factor with the same length as
xrepresenting the secondary sampling unit (SSU). If provided, a schema (using theschemaargument) must be provided as well specifying the combinations of values inssuand cell values inweights. Within each PSU, a location can only be sampled in those grid cells ofweightswhose cell values fall within the range of its corresponding category inssuas defined inschema. For example,ssucould be a vector of place types (village, town, city) andschemacould be a list combining each place type to a corresponding number of people. In this case, a record inxidentified as being located in a village can only be sampled in raster cells with a low population density. If not provided, performs single-stage stratified sampling.- schema
An SSU schema object created by
ssu_schema. Only necessary ifssuis provided. A schema "translates" SSUs defined inssuto raster cells inweights. For example, if a SSU "town" is defined, what population values does this unit refer to?- ids
Optional vector used to identify sampling units in
x. Passed down to thefargument insplit. If a single ID identifies multiple geometries, they are merged usingst_combine. Useful if the boundaries of an administrative unit are dispersed over multiple geometries. If not provided (the default), each row identifies one sampling unit.- reuse_weights
If
TRUEandssuis provided, uses the weights dataset defined in theweightsargument both for generating SSUs and as a weights raster forwt_sample. This would result in a double weighting where locations can only be sampled in certain regions ofweightsand within these regions have a certain probability to be sampled in a specific part of the region. IfFALSE, performs random sampling after SSU assignment. Defaults toTRUEto reduce randomness. Ignored ifssuis not provided.Set to
FALSEif performance is at a premium or if this behavior is not desired. For example, in high-value regions of a population raster, the probability of people living in regions with lower population densities is still very high and might not be properly represented by weighted sampling. Generally, if the assignment of sampling zones usingschemais already detailed and leaves little space within each zone, reusing weights can be superfluous.Only relevant if the schema is threshold-based, i.e., the argument is silently ignored if the schema is of type ideal.
- composition
If computing composite weights (see section "Composite weights"), this argument controls the order of composition. If
"reductive"(the default), the provided weights are reduced to a single surface by taking the product of all weights layers. If"sequential", the weights are applied in their index order, that is, the second weight is only applied in the cells eligible after applying the first weight, and so on. When combined with relative schemas"sequential"is the safer option, as it prevents non-overlapping weights. However,"reductive"is the default because it is usually the expected behavior and does not impose an order on the weights.- smooth
If
TRUEand ifweightsis an object of classSpatRaster, computes focal statistics of the raster before entering grid weighting. Arguments tofocalcan be provided using thesmooth_optsargument. This can be useful if the values inauxrepresent spatially contiguous spatial entities like settlements or population centers.- smooth_opts
Arguments passed to
focal. Only relevant ifsmoothisTRUEandweightsis aSpatRaster.
Value
The geoimputed point geometries as an sfc, sf, or
SpatVector object. If x is an sf dataframe or
SpatVector with additional columns, the columns are kept and only
the geometry is updated.
Composite weights
You can provide composite weights instead of single weights by providing
named lists to weights, ssu, and schema. Whereas
single weights determine where geoimputation is allowed to sample based
on a single raster, composite weights are defined through multiple
combinations of rasters and SSUs. In particular, the geoimputation
algorithm is only allowed to sample inside the intersection of the provided
rasters. For example, if a population and an income raster are provided,
then high-income and rural individuals can only be sampled within
neighborhoods that exhibit high population and high income.
When providing composite weights, the names of the composite lists act
as identifiers for the weights. The arguments weights, ssu and
schema must have matching names. If the combination of raster
surfaces does not overlap, wt_strata silently unions the
surfaces and enables sampling in ALL weights rasters. See warn_union.
Examples
dummy <- dummy_data()
set.seed(123)
# Single-stage geoimputation
# Population-weighted sampling within PSUs
ssg <- wt_strata(dummy$survey, dummy$pop, psu = dummy$areas)
plot(
ssg["place_type"],
pch = 16,
main = "Single-state geoimputation",
extent = st_geometry(dummy$areas), # Forces the plot to fit the polygon size
reset = FALSE
)
plot(dummy$areas, add = TRUE)
# Two-stage geoimputation
# Population- and survey-weighted sampling within PSUs
schema <- proto_schema(dummy$pop, dummy$survey$place_type)
tsg <- wt_strata(
dummy$survey,
dummy$pop,
psu = dummy$areas,
ssu = dummy$survey$place_type,
schema = schema
)
plot(
tsg["place_type"],
pch = 16,
main = "Two-state geoimputation",
extent = st_geometry(dummy$areas), # Forces the plot to fit the polygon size
reset = FALSE
)
plot(dummy$areas, add = TRUE)
