Currently, there are 9 functions associated with the
sample verb in the sgsR package:
| Algorithm | Description | Reference |
|---|---|---|
sample_srs() |
Simple random | |
sample_systematic() |
Systematic | |
sample_strat() |
Stratified | Queinnec, White, & Coops (2021) |
sample_sys_strat() |
Systematic Stratified | |
sample_nc() |
Nearest centroid | Melville & Stone (2016) |
sample_clhs() |
Conditioned Latin hypercube | Minasny & McBratney (2006) |
sample_balanced() |
Balanced sampling | Grafström, A. Lisic, J (2018) |
sample_ahels() |
Adapted hypercube evaluation of a legacy sample | Malone, Minasny, & Brungard (2019) |
sample_existing() |
Sub-sampling an existing sample |
sample_srsWe have demonstrated a simple example of using the
sample_srs() function in vignette("sgsR"). We
will demonstrate additional examples below.
raster
The input required for sample_srs() is a
raster. This means that sraster and
mraster are supported for this function.
#--- perform simple random sampling ---#
sample_srs(
raster = sraster, # input sraster
nSamp = 200, # number of desired sample units
plot = TRUE
) # plot#> Simple feature collection with 200 features and 0 fields
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 431130 ymin: 5337730 xmax: 438530 ymax: 5343170
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#> geometry
#> 1 POINT (433530 5339430)
#> 2 POINT (433930 5339630)
#> 3 POINT (438510 5339390)
#> 4 POINT (431910 5338570)
#> 5 POINT (435390 5342750)
#> 6 POINT (437610 5342850)
#> 7 POINT (432730 5342570)
#> 8 POINT (436410 5342710)
#> 9 POINT (431550 5339570)
#> 10 POINT (434890 5339650)
sample_srs(
raster = mraster, # input mraster
nSamp = 200, # number of desired sample units
access = access, # define access road network
mindist = 200, # minimum distance sample units must be apart from one another
buff_inner = 50, # inner buffer - no sample units within this distance from road
buff_outer = 200, # outer buffer - no sample units further than this distance from road
plot = TRUE
) # plot#> Simple feature collection with 200 features and 0 fields
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 431110 ymin: 5337730 xmax: 438550 ymax: 5343230
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#> geometry
#> 1 POINT (437250 5338370)
#> 2 POINT (434550 5339930)
#> 3 POINT (437170 5341710)
#> 4 POINT (432210 5341750)
#> 5 POINT (431690 5340850)
#> 6 POINT (433970 5342610)
#> 7 POINT (434830 5338910)
#> 8 POINT (435950 5342090)
#> 9 POINT (438150 5337830)
#> 10 POINT (432590 5341770)
sample_systematicThe sample_systematic() function applies systematic
sampling across an area with the cellsize parameter
defining the resolution of the tessellation. The tessellation shape can
be modified using the square parameter. Assigning
TRUE (default) to the square parameter results
in a regular grid and assigning FALSE results in a
hexagonal grid.
The location of sample units can also be adjusted using the
locations parameter, where centers takes the
center, corners takes all corners, and random
takes a random location within each tessellation. Random start points
and translations are applied when the function is called.
#--- perform grid sampling ---#
sample_systematic(
raster = sraster, # input sraster
cellsize = 1000, # grid distance
plot = TRUE
) # plot#> Simple feature collection with 34 features and 0 fields
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 431307.4 ymin: 5337801 xmax: 438489.5 ymax: 5343101
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#> geometry
#> 1 POINT (431934.5 5342646)
#> 2 POINT (431307.4 5341867)
#> 3 POINT (433340.5 5342798)
#> 4 POINT (432086.4 5341240)
#> 5 POINT (431459.4 5340461)
#> 6 POINT (434746.6 5342950)
#> 7 POINT (434119.5 5342171)
#> 8 POINT (433492.4 5341392)
#> 9 POINT (432865.4 5340613)
#> 10 POINT (436152.6 5343101)
#--- perform grid sampling ---#
sample_systematic(
raster = sraster, # input sraster
cellsize = 500, # grid distance
square = FALSE, # hexagonal tessellation
location = "random", # randomly sample within tessellation
plot = TRUE
) # plot#> Simple feature collection with 169 features and 0 fields
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 431147.9 ymin: 5337711 xmax: 438520.1 ymax: 5343198
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#> geometry
#> 1 POINT (431234.9 5338118)
#> 2 POINT (433392 5337720)
#> 3 POINT (432469.4 5338042)
#> 4 POINT (431815.4 5338169)
#> 5 POINT (433172 5337904)
#> 6 POINT (432429.6 5338284)
#> 7 POINT (431356.6 5338793)
#> 8 POINT (434475.3 5337812)
#> 9 POINT (433706.5 5338037)
#> 10 POINT (432638 5338416)
sample_systematic(
raster = sraster, # input sraster
cellsize = 500, # grid distance
access = access, # define access road network
buff_outer = 200, # outer buffer - no sample units further than this distance from road
square = FALSE, # hexagonal tessellation
location = "corners", # take corners instead of centers
plot = TRUE
)#> Simple feature collection with 636 features and 0 fields
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 431191.4 ymin: 5337724 xmax: 438487.6 ymax: 5343237
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#> geometry
#> 1 POINT (438487.6 5338488)
#> 2 POINT (438487.6 5338488)
#> 3 POINT (438254.9 5338659)
#> 4 POINT (438286.6 5338946)
#> 5 POINT (438159.9 5337798)
#> 6 POINT (438191.6 5338085)
#> 7 POINT (438244.2 5340838)
#> 8 POINT (438275.8 5341125)
#> 9 POINT (438149.1 5339977)
#> 10 POINT (438180.8 5340264)
sample_stratThe sample_strat() contains two methods to
perform sampling:
"Queinnec" - Hierarchical sampling using a focal
window to isolate contiguous groups of stratum pixels, which was
originally developed by Martin Queinnec.
"random" - Traditional stratified random sampling.
This method ignores much of the functionality of the
algorithm to allow users the capability to use standard stratified
random sampling approaches without the use of a focal window to locate
contiguous stratum cells.
method = "Queinnec"Queinnec, M., White, J. C., & Coops, N. C. (2021). Comparing airborne and spaceborne photon-counting LiDAR canopy structural estimates across different boreal forest types. Remote Sensing of Environment, 262(August 2020), 112510.
This algorithm uses moving window (wrow and
wcol parameters) to filter the input sraster
to prioritize sample unit allocation to where stratum pixels are
spatially grouped, rather than dispersed individuals across the
landscape.
Sampling is performed using 2 rules:
Rule 1 - Sample within spatially grouped stratum
pixels. Moving window defined by wrow and
wcol.
Rule 2 - If no additional sample units exist to
satisfy desired sample size(nSamp), individual stratum
pixels are sampled.
The rule applied to a select each sample unit is defined in the
rule attribute of output samples. We give a few examples
below:
#--- perform stratified sampling random sampling ---#
sample_strat(
sraster = sraster, # input sraster
nSamp = 200
) # desired sample size # plot
#> Simple feature collection with 200 features and 3 fields
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 431190 ymin: 5337730 xmax: 438530 ymax: 5343150
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#> strata type rule geometry
#> x 1 new rule1 POINT (436010 5342550)
#> x1 1 new rule1 POINT (433930 5341010)
#> x2 1 new rule1 POINT (437510 5338610)
#> x3 1 new rule1 POINT (437650 5339230)
#> x4 1 new rule1 POINT (437930 5340850)
#> x5 1 new rule1 POINT (436010 5342670)
#> x6 1 new rule1 POINT (438250 5340970)
#> x7 1 new rule1 POINT (438210 5338230)
#> x8 1 new rule1 POINT (435390 5342010)
#> x9 1 new rule1 POINT (434290 5340770)In some cases, users might want to include an existing
sample within the algorithm. In order to adjust the total number of
sample units needed per stratum to reflect those already present in
existing, we can use the intermediate function
extract_strata().
This function uses the sraster and existing
sample units and extracts the stratum for each. These sample units can
be included within sample_strat(), which adjusts total
sample units required per class based on representation in
existing.
#--- extract strata values to existing samples ---#
e.sr <- extract_strata(
sraster = sraster, # input sraster
existing = existing
) # existing samples to add strata value toTIP!
sample_strat() requires the sraster input
to have an attribute named strata and will give an error if
it doesn’t.
sample_strat(
sraster = sraster, # input sraster
nSamp = 200, # desired sample size
access = access, # define access road network
existing = e.sr, # existing sample with strata values
mindist = 200, # minimum distance sample units must be apart from one another
buff_inner = 50, # inner buffer - no sample units within this distance from road
buff_outer = 200, # outer buffer - no sample units further than this distance from road
plot = TRUE
) # plot#> Simple feature collection with 400 features and 3 fields
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 431150 ymin: 5337710 xmax: 438530 ymax: 5343230
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#> strata type rule geometry
#> 1 1 existing existing POINT (435750 5339390)
#> 2 1 existing existing POINT (435510 5342170)
#> 3 1 existing existing POINT (434510 5342810)
#> 4 1 existing existing POINT (437890 5342470)
#> 5 1 existing existing POINT (434670 5341530)
#> 6 1 existing existing POINT (435810 5342230)
#> 7 1 existing existing POINT (433570 5341530)
#> 8 1 existing existing POINT (437350 5338090)
#> 9 1 existing existing POINT (437590 5339010)
#> 10 1 existing existing POINT (437050 5338110)
The code in the example above defined the mindist
parameter, which specifies the minimum euclidean distance that new
sample units must be apart from one another.
Notice that the sample units have type and
rule attributes which outline whether they are
existing or new, and whether
rule1 or rule2 were used to select them. If
type is existing (a user provided
existing sample), rule will be
existing as well as seen above.
sample_strat(
sraster = sraster, # input
nSamp = 200, # desired sample size
access = access, # define access road network
existing = e.sr, # existing samples with strata values
include = TRUE, # include existing sample in nSamp total
buff_outer = 200, # outer buffer - no samples further than this distance from road
plot = TRUE
) # plot#> Simple feature collection with 200 features and 3 fields
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 431150 ymin: 5337750 xmax: 438530 ymax: 5343150
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#> strata type rule geometry
#> 1 1 existing existing POINT (435750 5339390)
#> 2 1 existing existing POINT (435510 5342170)
#> 3 1 existing existing POINT (434510 5342810)
#> 4 1 existing existing POINT (437890 5342470)
#> 5 1 existing existing POINT (434670 5341530)
#> 6 1 existing existing POINT (435810 5342230)
#> 7 1 existing existing POINT (433570 5341530)
#> 8 1 existing existing POINT (437350 5338090)
#> 9 1 existing existing POINT (437590 5339010)
#> 10 1 existing existing POINT (437050 5338110)
The include parameter determines whether
existing sample units should be included in the total
sample size defined by nSamp. By default, the
include parameter is set as FALSE.
method = "randomStratified random sampling with equal probability for all cells
(using default algorithm values for mindist and no use of
access functionality). In essence this method perform the
sample_srs algorithm for each stratum separately to meet
the specified sample size.
#--- perform stratified sampling random sampling ---#
sample_strat(
sraster = sraster, # input sraster
method = "random", # stratified random sampling
nSamp = 200, # desired sample size
plot = TRUE
) # plot#> Simple feature collection with 200 features and 2 fields
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 431130 ymin: 5337770 xmax: 438550 ymax: 5343230
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#> strata type geometry
#> x 1 new POINT (436070 5342930)
#> x1 1 new POINT (434930 5339590)
#> x2 1 new POINT (436790 5338930)
#> x3 1 new POINT (433610 5339370)
#> x4 1 new POINT (433150 5340910)
#> x5 1 new POINT (433590 5340950)
#> x6 1 new POINT (438430 5339190)
#> x7 1 new POINT (438510 5339430)
#> x8 1 new POINT (434410 5342690)
#> x9 1 new POINT (434330 5341290)
sample_sys_stratsample_sys_strat() function implements systematic
stratified sampling on an sraster. This function uses the
same functionality as sample_systematic() but takes an
sraster as input and performs sampling on each stratum
iteratively.
#--- perform grid sampling on each stratum separately ---#
sample_sys_strat(
sraster = sraster, # input sraster with 4 strata
cellsize = 1000, # grid size
plot = TRUE # plot output
)
#> Warning: [readStart] source already open for reading
#> Processing strata : 1
#> Warning: [extract] source already open for reading
#> Processing strata : 2
#> Warning: [extract] source already open for reading
#> Processing strata : 3
#> Warning: [extract] source already open for reading
#> Processing strata : 4
#> Warning: [extract] source already open for reading#> Simple feature collection with 32 features and 1 field
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 431138.8 ymin: 5337842 xmax: 438480.9 ymax: 5343143
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#> strata geometry
#> 1 1 POINT (437519.9 5342935)
#> 2 1 POINT (435392.9 5342246)
#> 3 1 POINT (434404.1 5342395)
#> 4 1 POINT (434254.6 5341406)
#> 5 1 POINT (433265.8 5341556)
#> 6 1 POINT (432127.6 5340717)
#> 7 1 POINT (431138.8 5340866)
#> 8 1 POINT (437910.7 5338831)
#> 9 1 POINT (437761.2 5337842)
#> 10 1 POINT (436772.5 5337992)
Just like with sample_systematic() we can specify where
we want our samples to fall within our tessellations. We specify
location = "corners" below. Note that the tesselations are
all saved to a list file when details = TRUE should the
user want to save them.
sample_sys_strat(
sraster = sraster, # input sraster with 4 strata
cellsize = 500, # grid size
square = FALSE, # hexagon tessellation
location = "corners", # samples on tessellation corners
plot = TRUE # plot output
)
#> Processing strata : 1
#> Warning: [extract] source already open for reading
#> Processing strata : 2
#> Warning: [extract] source already open for reading
#> Processing strata : 3
#> Warning: [extract] source already open for reading
#> Processing strata : 4
#> Warning: [extract] source already open for reading#> Simple feature collection with 1159 features and 1 field
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 431113.2 ymin: 5337714 xmax: 438549.4 ymax: 5343220
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#> strata geometry
#> 1 1 POINT (431150.4 5340638)
#> 2 1 POINT (431150.4 5340638)
#> 3 1 POINT (431417 5340748)
#> 4 1 POINT (431150.4 5340638)
#> 5 1 POINT (431150.4 5340638)
#> 6 1 POINT (431417 5340748)
#> 7 1 POINT (431646.2 5340573)
#> 8 1 POINT (431646.2 5340573)
#> 9 1 POINT (431417 5340748)
#> 10 1 POINT (431646.2 5340573)
This sampling approach could be especially useful incombination with
strat_poly() to ensure consistency of sampling accross
specific management units.
#--- read polygon coverage ---#
poly <- system.file("extdata", "inventory_polygons.shp", package = "sgsR")
fri <- sf::st_read(poly)
#> Reading layer `inventory_polygons' from data source
#> `/tmp/RtmpB07Dc1/Rinst12f362b4bd44/sgsR/extdata/inventory_polygons.shp'
#> using driver `ESRI Shapefile'
#> Simple feature collection with 632 features and 3 fields
#> Geometry type: MULTIPOLYGON
#> Dimension: XY
#> Bounding box: xmin: 431100 ymin: 5337700 xmax: 438560 ymax: 5343240
#> Projected CRS: UTM_Zone_17_Northern_Hemisphere
#--- stratify polygon coverage ---#
#--- specify polygon attribute to stratify ---#
attribute <- "NUTRIENTS"
#--- specify features within attribute & how they should be grouped ---#
#--- as a single vector ---#
features <- c("poor", "rich", "medium")
#--- get polygon stratification ---#
srasterpoly <- strat_poly(
poly = fri,
attribute = attribute,
features = features,
raster = sraster
)
#--- systematatic stratified sampling for each stratum ---#
sample_sys_strat(
sraster = srasterpoly, # input sraster from strat_poly() with 3 strata
cellsize = 500, # grid size
square = FALSE, # hexagon tessellation
location = "random", # randomize plot location
plot = TRUE # plot output
)
#> Processing strata : 1
#> Warning: [extract] source already open for reading
#> Processing strata : 2
#> Warning: [extract] source already open for reading
#> Processing strata : 3
#> Warning: [extract] source already open for reading
#> Simple feature collection with 158 features and 1 field
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 431193.1 ymin: 5337706 xmax: 438555.4 ymax: 5343210
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#> strata geometry
#> 1 1 POINT (438295 5338198)
#> 2 1 POINT (437966.7 5338239)
#> 3 1 POINT (438324.2 5338460)
#> 4 1 POINT (437228.2 5338214)
#> 5 1 POINT (436524.8 5337977)
#> 6 1 POINT (436992.5 5338402)
#> 7 1 POINT (434875 5337861)
#> 8 1 POINT (437623.1 5339032)
#> 9 1 POINT (433422.3 5337863)
#> 10 1 POINT (437795.7 5339556)sample_ncsample_nc() function implements the Nearest Centroid
sampling algorithm described in Melville &
Stone (2016). The algorithm uses kmeans clustering where the number
of clusters (centroids) is equal to the desired sample size
(nSamp).
Cluster centers are located, which then prompts the nearest neighbour
mraster pixel for each cluster to be selected (assuming
default k parameter). These nearest neighbours are the
output sample units.
#--- perform simple random sampling ---#
sample_nc(
mraster = mraster, # input
nSamp = 25, # desired sample size
plot = TRUE
)
#> K-means being performed on 3 layers with 25 centers.#> Simple feature collection with 25 features and 4 fields
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 431150 ymin: 5338150 xmax: 438310 ymax: 5343030
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#> zq90 pzabove2 zsd kcenter geometry
#> 49476 21.90 92.7 5.30 1 POINT (435890 5340590)
#> 16795 6.57 13.6 1.75 2 POINT (431290 5342330)
#> 38874 16.30 94.2 2.88 3 POINT (432730 5341150)
#> 36670 2.92 6.6 0.58 4 POINT (433410 5341270)
#> 56502 17.40 78.0 4.66 5 POINT (434670 5340210)
#> 52434 20.80 22.1 6.89 6 POINT (435370 5340430)
#> 16979 4.55 32.1 1.02 7 POINT (434970 5342330)
#> 73674 23.20 88.9 6.68 8 POINT (434950 5339290)
#> 73725 9.72 60.4 2.50 9 POINT (435970 5339290)
#> 32048 26.50 87.4 8.24 10 POINT (437950 5341530)
Altering the k parameter leads to a multiplicative
increase in output sample units where total output samples = \(nSamp * k\).
#--- perform simple random sampling ---#
samples <- sample_nc(
mraster = mraster, # input
k = 2, # number of nearest neighbours to take for each kmeans center
nSamp = 25, # desired sample size
plot = TRUE
)
#> K-means being performed on 3 layers with 25 centers.Visualizing what the kmeans centers and sample units looks like is
possible when using details = TRUE. The $kplot
output provides a quick visualization of where the centers are based on
a scatter plot of the first 2 layers in mraster. Notice
that the centers are well distributed in covariate space and chosen
sample units are the closest pixels to each center (nearest
neighbours).
#--- perform simple random sampling with details ---#
details <- sample_nc(
mraster = mraster, # input
nSamp = 25, # desired sample number
details = TRUE
)
#> K-means being performed on 3 layers with 25 centers.
#--- plot ggplot output ---#
details$kplotsample_clhssample_clhs() function implements conditioned Latin
hypercube (clhs) sampling methodology from the clhs
package.
TIP!
A number of other functions in the sgsR package help to
provide guidance on clhs sampling including calculate_pop()
and calculate_lhsOpt(). Check out these functions to better
understand how sample numbers could be optimized.
The syntax for this function is similar to others shown above,
although parameters like iter, which define the number of
iterations within the Metropolis-Hastings process are important to
consider. In these examples we use a low iter value for
efficiency. Default values for iter within the
clhs package are 10,000.
sample_clhs(
mraster = mraster, # input
nSamp = 200, # desired sample size
plot = TRUE, # plot
iter = 100
) # number of iterationsThe cost parameter defines the mraster
covariate, which is used to constrain the clhs sampling. An example
could be the distance a pixel is from road access
(e.g. from calculate_distance() see example below), terrain
slope, the output from calculate_coobs(), or many
others.
#--- cost constrained examples ---#
#--- calculate distance to access layer for each pixel in mr ---#
mr.c <- calculate_distance(
raster = mraster, # input
access = access, # define access road network
plot = TRUE
) # plotsample_clhs(
mraster = mr.c, # input
nSamp = 250, # desired sample size
iter = 100, # number of iterations
cost = "dist2access", # cost parameter - name defined in calculate_distance()
plot = TRUE
) # plotsample_balancedThe sample_balanced() algorithm performs a balanced
sampling methodology from the stratifyR / SamplingBigData
packages.
#> Simple feature collection with 200 features and 0 fields
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 431110 ymin: 5337710 xmax: 438550 ymax: 5343230
#> Projected CRS: +proj=utm +zone=17 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs
#> First 10 features:
#> geometry
#> 1 POINT (435410 5343230)
#> 2 POINT (437990 5343190)
#> 3 POINT (438130 5343190)
#> 4 POINT (435050 5343170)
#> 5 POINT (434610 5343150)
#> 6 POINT (437890 5343050)
#> 7 POINT (431590 5343010)
#> 8 POINT (431910 5342970)
#> 9 POINT (432570 5342970)
#> 10 POINT (432610 5342970)
sample_balanced(
mraster = mraster, # input
nSamp = 100, # desired sample size
algorithm = "lcube", # algorithm type
access = access, # define access road network
buff_inner = 50, # inner buffer - no sample units within this distance from road
buff_outer = 200
) # outer buffer - no sample units further than this distance from road
#> Simple feature collection with 100 features and 0 fields
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 431250 ymin: 5337730 xmax: 438410 ymax: 5343130
#> Projected CRS: +proj=utm +zone=17 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs
#> First 10 features:
#> geometry
#> 1 POINT (436370 5343130)
#> 2 POINT (433750 5343030)
#> 3 POINT (433570 5343010)
#> 4 POINT (434850 5342950)
#> 5 POINT (435770 5342890)
#> 6 POINT (437770 5342850)
#> 7 POINT (433570 5342750)
#> 8 POINT (434590 5342730)
#> 9 POINT (431250 5342710)
#> 10 POINT (433030 5342690)sample_ahelsThe sample_ahels() function performs the adapted
Hypercube Evaluation of a Legacy Sample (ahels) algorithm
usingexisting sample data and an mraster. New
sample units are allocated based on quantile ratios between the
existing sample and mraster covariate
dataset.
This algorithm was adapted from that presented in the paper below, which we highly recommend.
Malone BP, Minansy B, Brungard C. 2019. Some methods to improve the utility of conditioned Latin hypercube sampling. PeerJ 7:e6451 DOI 10.7717/peerj.6451
This algorithm:
Determines the quantile distributions of existing
sample units and mraster covariates.
Determines quantiles where there is a disparity between sample units and covariates.
Prioritizes sampling within those quantile to improve representation.
To use this function, user must first specify the number of quantiles
(nQuant) followed by either the nSamp (total
number of desired sample units to be added) or the
threshold (sampling ratio vs. covariate coverage ratio for
quantiles - default is 0.9) parameters.
#--- remove `type` variable from existing - causes plotting issues ---#
existing <- existing %>% select(-type)
sample_ahels(
mraster = mraster,
existing = existing, # existing sample
plot = TRUE
) # plot#> Simple feature collection with 309 features and 7 fields
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 431150 ymin: 5337750 xmax: 438550 ymax: 5343210
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#> type.x zq90 pzabove2 zsd strata type.y rule geometry
#> 1 existing 7.47 34.1 1.79 1 new rule1 POINT (435750 5339390)
#> 2 existing 4.38 44.6 0.92 1 new rule1 POINT (435510 5342170)
#> 3 existing 8.84 81.7 2.11 1 new rule1 POINT (434510 5342810)
#> 4 existing 2.15 0.6 0.26 1 new rule1 POINT (437890 5342470)
#> 5 existing 3.72 14.6 0.77 1 new rule1 POINT (434670 5341530)
#> 6 existing 8.25 59.9 2.15 1 new rule1 POINT (435810 5342230)
#> 7 existing 3.79 10.0 0.86 1 new rule1 POINT (433570 5341530)
#> 8 existing 8.32 68.2 1.94 1 new rule1 POINT (437350 5338090)
#> 9 existing 2.73 11.9 0.46 1 new rule1 POINT (437590 5339010)
#> 10 existing 7.09 71.5 1.55 1 new rule1 POINT (437050 5338110)
TIP!
Notice that no threshold, nSamp, or
nQuant were defined. That is because the default setting
for threshold = 0.9 and nQuant = 10.
The first matrix output shows the quantile ratios between the sample and the covariates. A value of 1.0 indicates that the sample is representative of quantile coverage. Values > 1.0 indicate over representation of sample units, while < 1.0 indicate under representation.
sample_ahels(
mraster = mraster,
existing = existing, # existing sample
nQuant = 20, # define 20 quantiles
nSamp = 300
) # desired sample size#> Simple feature collection with 500 features and 7 fields
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 431110 ymin: 5337710 xmax: 438530 ymax: 5343170
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#> type.x zq90 pzabove2 zsd strata type.y rule geometry
#> 1 existing 7.47 34.1 1.79 1 new rule1 POINT (435750 5339390)
#> 2 existing 4.38 44.6 0.92 1 new rule1 POINT (435510 5342170)
#> 3 existing 8.84 81.7 2.11 1 new rule1 POINT (434510 5342810)
#> 4 existing 2.15 0.6 0.26 1 new rule1 POINT (437890 5342470)
#> 5 existing 3.72 14.6 0.77 1 new rule1 POINT (434670 5341530)
#> 6 existing 8.25 59.9 2.15 1 new rule1 POINT (435810 5342230)
#> 7 existing 3.79 10.0 0.86 1 new rule1 POINT (433570 5341530)
#> 8 existing 8.32 68.2 1.94 1 new rule1 POINT (437350 5338090)
#> 9 existing 2.73 11.9 0.46 1 new rule1 POINT (437590 5339010)
#> 10 existing 7.09 71.5 1.55 1 new rule1 POINT (437050 5338110)
Notice that the total number of samples is 500. This value is the sum
of existing units (200) and number of sample units defined by
nSamp = 300.
sample_existingAcknowledging that existing sample networks are common
is important. There is significant investment into these samples, and in
order to keep inventories up-to-date, we often need to collect new data
for sample units. The sample_existing algorithm provides
the user with methods for sub-sampling an existing sample
network should the financial / logistical resources not be available to
collect data at all sample units. The functions allows users to choose
between algorithm types using (type = "clhs" - default,
type = "balanced", type = "srs",
type = "strat"). Differences in type result in calling
internal sample_existing_*() functions
(sample_existing_clhs() (default),
sample_existing_balanced(),
sample_existing_srs(),
sample_existing_strat()). These functions are not exported
to be used stand-alone, however they employ the same functionality as
their sample_clhs() etc counterparts.
While using sample_existing(), should the user wish to
specify algorithm specific parameters
(e.g. algorithm = "lcube" in sample_balanced()
or allocation = "equal" in sample_strat()),
they can specify within sample_existing() as if calling the
function directly.
I give applied examples for all methods below that are based on the following scenario:
We have a systematic sample where sample units are 200m apart.
We know we only have resources to sample 300 of them.
We have some ALS data available (mraster), which we
can use to improve knowledge of the metric populations.
See our existing sample for the scenario below.
#--- generate existing samples and extract metrics ---#
existing <- sample_systematic(raster = mraster, cellsize = 200, plot = TRUE)sample_existing(type = "clhs")The algorithm is unique in that it has two fundamental approaches:
existing and the attributes it
contains.#--- sub sample using ---#
sample_existing(existing = e, nSamp = 300, type = "clhs")
#> Simple feature collection with 300 features and 3 fields
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 431106.9 ymin: 5337717 xmax: 438559.9 ymax: 5343196
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#> zq90 pzabove2 zsd geometry
#> 270 4.20 17.6 0.98 POINT (434363.7 5341586)
#> 554 11.40 67.6 2.97 POINT (438329.3 5340898)
#> 401 18.30 64.7 5.65 POINT (437658.6 5341740)
#> 890 12.60 45.7 3.53 POINT (438310.8 5338177)
#> 694 13.70 86.3 3.40 POINT (437218.5 5339729)
#> 844 10.00 85.0 2.68 POINT (437946.7 5338695)
#> 822 11.60 15.7 3.79 POINT (438463.8 5339059)
#> 172 10.90 91.5 2.75 POINT (432084.1 5341528)
#> 563 24.50 90.6 7.29 POINT (436413.8 5340323)
#> 792 8.55 39.6 2.22 POINT (435667.1 5338637)raster distributionsOur systematic sample of ~900 plots is fairly comprehensive, however
we can generate a true population distribution through the inclusion of
the ALS metrics in the sampling process. The metrics will be included in
internal latin hypercube sampling to help guide sub-sampling of
existing.
#--- sub sample using ---#
sample_existing(
existing = existing, # our existing sample
nSamp = 300, # desired sample size
raster = mraster, # include mraster metrics to guide sampling of existing
plot = TRUE
) # plot
#> Simple feature collection with 300 features and 3 fields
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 431184.4 ymin: 5337717 xmax: 438539.9 ymax: 5343234
#> Projected CRS: +proj=utm +zone=17 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs
#> First 10 features:
#> zq90 pzabove2 zsd geometry
#> 91464 4.35 26.7 1.39 POINT (434555.3 5341644)
#> 91793 23.70 84.1 8.52 POINT (435322 5339786)
#> 91742 22.30 86.9 7.03 POINT (433099.9 5339536)
#> 92074 13.60 14.9 4.70 POINT (438061.7 5338311)
#> 92044 8.47 87.8 2.01 POINT (436797.4 5338350)
#> 91828 21.40 95.5 4.80 POINT (434804.8 5339422)
#> 91889 13.70 86.3 3.40 POINT (437218.5 5339729)
#> 91398 3.91 13.3 1.03 POINT (433099.4 5341624)
#> 91728 19.00 81.4 3.56 POINT (436356.3 5340514)
#> 91847 5.55 15.6 1.33 POINT (438501.8 5340323)The sample distribution again mimics the population distribution quite well! Now lets try using a cost variable to constrain the sub-sample.
#--- create distance from roads metric ---#
dist <- calculate_distance(raster = mraster, access = access)#--- sub sample using ---#
sample_existing(
existing = existing, # our existing sample
nSamp = 300, # desired sample size
raster = dist, # include mraster metrics to guide sampling of existing
cost = 4, # either provide the index (band number) or the name of the cost layer
plot = TRUE
) # plot
#> Simple feature collection with 300 features and 4 fields
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 431106.9 ymin: 5337717 xmax: 438482.3 ymax: 5343234
#> Projected CRS: +proj=utm +zone=17 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs
#> First 10 features:
#> zq90 pzabove2 zsd dist2access geometry
#> 92044 8.47 87.8 2.01 86.50000 POINT (436797.4 5338350)
#> 91452 18.70 89.8 4.72 519.57457 POINT (436853.9 5342334)
#> 91688 11.20 96.7 2.00 89.23967 POINT (438022.7 5341223)
#> 91665 20.50 90.4 4.97 26.54215 POINT (436241.2 5340897)
#> 91563 24.30 93.1 8.51 45.84249 POINT (437218 5341817)
#> 91215 7.01 64.4 1.31 29.48566 POINT (433079.9 5343080)
#> 91806 17.40 91.3 4.28 16.14371 POINT (432831.8 5339038)
#> 91855 9.75 85.1 2.41 683.00165 POINT (436969.4 5339863)
#> 91986 3.32 10.8 0.69 95.67315 POINT (437582.6 5339212)
#> 91682 14.80 90.7 3.79 393.93464 POINT (432218.6 5339689)Finally, should the user wish to further constrain the sample based
on access like other sampling approaches in
sgsR that is also possible.
#--- ensure access and existing are in the same CRS ---#
sf::st_crs(existing) <- sf::st_crs(access)
#--- sub sample using ---#
sample_existing(
existing = existing, # our existing sample
nSamp = 300, # desired sample size
raster = dist, # include mraster metrics to guide sampling of existing
cost = 4, # either provide the index (band number) or the name of the cost layer
access = access, # roads layer
buff_inner = 50, # inner buffer - no sample units within this distance from road
buff_outer = 300, # outer buffer - no sample units further than this distance from road
plot = TRUE
) # plot
#> Simple feature collection with 300 features and 4 fields
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 431106.9 ymin: 5337737 xmax: 438559.9 ymax: 5343234
#> Projected CRS: +proj=utm +zone=17 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs
#> First 10 features:
#> zq90 pzabove2 zsd dist2access geometry
#> 91531 11.10 79.2 2.70 174.04739 POINT (437927.2 5340150)
#> 91500 15.60 69.3 4.73 59.36660 POINT (435896.6 5339958)
#> 91631 23.30 86.2 5.67 89.30918 POINT (435514 5337755)
#> 91393 24.60 91.2 6.79 165.64092 POINT (432563.2 5340628)
#> 91207 11.30 55.9 2.91 163.99318 POINT (432696.8 5342965)
#> 91277 16.60 91.5 4.40 164.72747 POINT (436489.8 5342851)
#> 91598 16.80 95.4 3.10 141.41798 POINT (438080.7 5338944)
#> 91204 8.09 64.0 3.36 96.69617 POINT (431106.9 5342697)
#> 91527 15.40 93.8 3.78 123.30146 POINT (432506.2 5338732)
#> 91635 11.10 3.0 3.66 239.04370 POINT (437678.6 5338196)TIP!
The greater constraints we add to sampling, the less likely we will have strong correlations between the population and sample, so its always important to understand these limitations and plan accordingly.
sample_existing(type = "balanced")When type = "balanced" users can define all parameters
that are found within sample_balanced(). This means that
one can change the algorithm, p etc.
sample_existing(existing = e, nSamp = 300, type = "balanced")
#> Simple feature collection with 300 features and 3 fields
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 431106.9 ymin: 5337737 xmax: 438559.9 ymax: 5343196
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#> zq90 pzabove2 zsd geometry
#> 5 19.50 89.0 3.55 POINT (431815.5 5343118)
#> 8 16.60 61.7 4.24 POINT (431240.9 5342946)
#> 13 20.10 77.5 5.68 POINT (431873.1 5342927)
#> 14 21.20 87.1 4.92 POINT (431681.5 5342869)
#> 16 18.90 76.2 4.58 POINT (431298.4 5342754)
#> 17 8.09 64.0 3.36 POINT (431106.9 5342697)
#> 22 11.30 55.9 2.91 POINT (432696.8 5342965)
#> 26 14.50 79.1 3.06 POINT (431930.6 5342735)
#> 27 19.40 85.8 3.44 POINT (431739 5342678)
#> 29 14.40 48.9 2.83 POINT (431355.9 5342563)sample_existing(existing = e, nSamp = 300, type = "balanced", algorithm = "lcube")
#> Simple feature collection with 300 features and 3 fields
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 431184.4 ymin: 5337716 xmax: 438559.9 ymax: 5343233
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#> zq90 pzabove2 zsd geometry
#> 1 20.90 80.8 5.43 POINT (431374.9 5343195)
#> 3 20.80 75.7 5.14 POINT (432198.6 5343233)
#> 4 16.50 3.5 5.48 POINT (432007.1 5343176)
#> 9 5.93 62.8 1.19 POINT (432830.8 5343214)
#> 10 15.50 69.8 3.46 POINT (432447.7 5343099)
#> 14 21.20 87.1 4.92 POINT (431681.5 5342869)
#> 19 15.00 26.6 4.26 POINT (433271.4 5343138)
#> 21 6.05 79.3 1.29 POINT (432888.3 5343023)
#> 25 12.80 71.9 2.91 POINT (432122.1 5342793)
#> 26 14.50 79.1 3.06 POINT (431930.6 5342735)sample_existing(type = "srs")The simplest, type = srs, randomly selects sample
units.
sample_existing(existing = e, nSamp = 300, type = "srs")
#> Simple feature collection with 300 features and 3 fields
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 431107.8 ymin: 5337737 xmax: 438559.9 ymax: 5343233
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#> zq90 pzabove2 zsd geometry
#> 1 8.55 39.6 2.22 POINT (435667.1 5338637)
#> 2 17.70 92.9 3.33 POINT (437428.6 5342507)
#> 3 11.30 88.6 3.03 POINT (433502.5 5338195)
#> 4 14.80 64.9 4.32 POINT (433118.9 5340169)
#> 5 12.50 67.5 3.10 POINT (433194.9 5342697)
#> 6 13.40 46.1 3.79 POINT (432620.3 5342525)
#> 7 12.20 85.2 3.38 POINT (432180.6 5338425)
#> 8 8.75 81.8 1.92 POINT (437946.2 5340783)
#> 9 8.45 59.2 2.24 POINT (435781.1 5342430)
#> 10 4.93 49.8 1.14 POINT (433846.6 5341222)sample_existing(type = "strat")When type = "strat", existing must have an
attribute named strata (just like how
sample_strat() requires a strata layer). If it
doesnt exist you will get an error. Lets define an sraster
so that we are compliant.
sraster <- strat_kmeans(mraster = mraster, nStrata = 4)
e_strata <- extract_strata(sraster = sraster, existing = e)When we do have a strata attribute, the function works very much the
same as sample_strat() in that is allows the user to define
the allocation method ("prop" - defaults,
"optim", "manual", "equal").
#--- proportional stratified sampling of existing ---#
sample_existing(existing = e_strata, nSamp = 300, type = "strat", allocation = "prop")
#> Simple feature collection with 301 features and 4 fields
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 431106.9 ymin: 5337716 xmax: 438559.9 ymax: 5343233
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#> strata zq90 pzabove2 zsd geometry
#> 1 2 19.9 86.9 5.31 POINT (437122.5 5340744)
#> 2 2 21.6 79.2 4.64 POINT (436739.4 5340629)
#> 3 2 20.0 91.9 6.06 POINT (438367.8 5340074)
#> 4 2 21.7 93.9 4.93 POINT (437045.9 5340304)
#> 5 2 21.4 41.6 5.37 POINT (432908.3 5339479)
#> 6 2 16.8 77.8 5.49 POINT (437160.5 5342008)
#> 7 2 18.8 90.0 4.86 POINT (435590.1 5340284)
#> 8 2 22.1 98.6 5.29 POINT (437007.4 5341127)
#> 9 2 17.8 48.7 5.30 POINT (431855 5338118)
#> 10 2 18.6 71.9 5.38 POINT (433329.4 5340858)TIP!
Remember that when allocation = "equal", the
nSamp value will be allocated for each strata.
We get 400 sample units in our output below because we have 4 strata
and nSamp = 100.
#--- equal stratified sampling of existing ---#
sample_existing(existing = e_strata, nSamp = 100, type = "strat", allocation = "equal")
#> Simple feature collection with 400 features and 4 fields
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 431106.9 ymin: 5337716 xmax: 438559.9 ymax: 5343233
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#> strata zq90 pzabove2 zsd geometry
#> 1 2 18.2 90.9 5.46 POINT (431471 5342180)
#> 2 2 20.0 92.1 5.02 POINT (434498.3 5339747)
#> 3 2 19.8 77.8 5.13 POINT (436566.8 5341204)
#> 4 2 19.1 90.8 5.69 POINT (437237 5342449)
#> 5 2 18.6 74.9 5.22 POINT (434575.3 5338100)
#> 6 2 20.8 86.1 6.26 POINT (435628.1 5341548)
#> 7 2 21.2 92.9 5.59 POINT (431701 5341413)
#> 8 2 18.3 64.7 5.65 POINT (437658.6 5341740)
#> 9 2 17.3 62.8 4.99 POINT (435129.9 5341816)
#> 10 2 16.4 80.6 5.41 POINT (436528.3 5342027)#--- manual stratified sampling of existing with user defined weights ---#
s <- sample_existing(existing = e_strata, nSamp = 100, type = "strat", allocation = "manual", weights = c(0.2, 0.6, 0.1, 0.1))We can check the proportion of samples from each strata with:
Finally, type = "optim allows for the user to define a
raster metric to be used to optimize within strata
variances.
#--- manual stratified sampling of existing with user defined weights ---#
sample_existing(existing = e_strata, nSamp = 100, type = "strat", allocation = "optim", raster = mraster, metric = "zq90")
#> Simple feature collection with 100 features and 4 fields
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 431107.8 ymin: 5337717 xmax: 438559.9 ymax: 5343233
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#> strata zq90 pzabove2 zsd geometry
#> 1 2 21.2 82.9 5.00 POINT (432294.7 5342218)
#> 2 2 18.3 58.4 4.84 POINT (433903.6 5343119)
#> 3 2 26.0 91.6 7.35 POINT (434096.2 5339000)
#> 4 2 20.0 90.2 5.93 POINT (431490 5342812)
#> 5 2 20.0 92.1 5.02 POINT (434498.3 5339747)
#> 6 2 20.9 81.6 6.43 POINT (433540.5 5339460)
#> 7 2 20.9 74.4 6.54 POINT (436030.7 5340208)
#> 8 2 21.5 51.6 6.74 POINT (432390.7 5341203)
#> 9 2 20.0 91.9 6.06 POINT (438367.8 5340074)
#> 10 2 20.8 86.1 6.26 POINT (435628.1 5341548)We see from the output that we get 300 sample units that are a
sub-sample of existing. The plotted output shows cumulative
frequency distributions of the population (all existing
samples) and the sub-sample (the 300 samples we requested).