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: 431170 ymin: 5337730 xmax: 438530 ymax: 5343230
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#> geometry
#> 1 POINT (436990 5342370)
#> 2 POINT (434590 5339850)
#> 3 POINT (432070 5343010)
#> 4 POINT (434150 5341650)
#> 5 POINT (435050 5341950)
#> 6 POINT (433130 5338650)
#> 7 POINT (433570 5340150)
#> 8 POINT (434550 5341550)
#> 9 POINT (432870 5340870)
#> 10 POINT (433410 5342130)
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: 431150 ymin: 5337710 xmax: 438470 ymax: 5343230
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#> geometry
#> 1 POINT (438030 5339370)
#> 2 POINT (433270 5342850)
#> 3 POINT (438130 5342090)
#> 4 POINT (436190 5341130)
#> 5 POINT (438010 5339050)
#> 6 POINT (437090 5341490)
#> 7 POINT (436790 5338150)
#> 8 POINT (436250 5343210)
#> 9 POINT (438210 5339590)
#> 10 POINT (434030 5341190)
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: 431577.7 ymin: 5337718 xmax: 438506.8 ymax: 5343169
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#> geometry
#> 1 POINT (436766.3 5337948)
#> 2 POINT (438506.8 5338933)
#> 3 POINT (434533.2 5337833)
#> 4 POINT (435403.4 5338326)
#> 5 POINT (438014.2 5339803)
#> 6 POINT (432300 5337718)
#> 7 POINT (433170.3 5338211)
#> 8 POINT (434040.6 5338703)
#> 9 POINT (434910.9 5339196)
#> 10 POINT (435781.1 5339688)
#--- 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 167 features and 0 fields
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 431170.1 ymin: 5337734 xmax: 438546.1 ymax: 5343212
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#> geometry
#> 1 POINT (438431.7 5342706)
#> 2 POINT (437897.2 5343212)
#> 3 POINT (438236.3 5342350)
#> 4 POINT (438546.1 5341509)
#> 5 POINT (437750.4 5342586)
#> 6 POINT (438220.4 5340999)
#> 7 POINT (438294.3 5340087)
#> 8 POINT (437563.4 5343107)
#> 9 POINT (437738.3 5342336)
#> 10 POINT (438039.1 5341457)
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 650 features and 0 fields
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 431222.2 ymin: 5337734 xmax: 438531.6 ymax: 5343226
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#> geometry
#> 1 POINT (438449.9 5337998)
#> 2 POINT (438477.2 5338497)
#> 3 POINT (438449.9 5337998)
#> 4 POINT (438003.9 5337772)
#> 5 POINT (438161.7 5338013)
#> 6 POINT (438449.9 5337998)
#> 7 POINT (438504.4 5338996)
#> 8 POINT (438477.2 5338497)
#> 9 POINT (438449.9 5337998)
#> 10 POINT (438161.7 5338013)
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: 431210 ymin: 5337730 xmax: 438530 ymax: 5343190
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#> strata type rule geometry
#> x 1 new rule1 POINT (433650 5340910)
#> x1 1 new rule1 POINT (433650 5341090)
#> x2 1 new rule1 POINT (432950 5341650)
#> x3 1 new rule1 POINT (438210 5339230)
#> x4 1 new rule1 POINT (437910 5339630)
#> x5 1 new rule1 POINT (437910 5342430)
#> x6 1 new rule1 POINT (437950 5338650)
#> x7 1 new rule1 POINT (433710 5341390)
#> x8 1 new rule1 POINT (433950 5341350)
#> x9 1 new rule1 POINT (434490 5342170)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: 431130 ymin: 5337730 xmax: 438530 ymax: 5343230
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#> strata type rule geometry
#> 1 1 existing existing POINT (435990 5339770)
#> 2 1 existing existing POINT (434310 5341470)
#> 3 1 existing existing POINT (433430 5341270)
#> 4 1 existing existing POINT (436990 5338010)
#> 5 1 existing existing POINT (437530 5338050)
#> 6 1 existing existing POINT (436070 5342310)
#> 7 1 existing existing POINT (434370 5340890)
#> 8 1 existing existing POINT (435250 5342070)
#> 9 1 existing existing POINT (431190 5340870)
#> 10 1 existing existing POINT (437890 5341210)
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: 431130 ymin: 5337790 xmax: 438530 ymax: 5343030
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#> strata type rule geometry
#> 1 1 existing existing POINT (435990 5339770)
#> 2 1 existing existing POINT (434310 5341470)
#> 3 1 existing existing POINT (433430 5341270)
#> 4 1 existing existing POINT (436990 5338010)
#> 5 1 existing existing POINT (437530 5338050)
#> 6 1 existing existing POINT (436070 5342310)
#> 7 1 existing existing POINT (434370 5340890)
#> 8 1 existing existing POINT (435250 5342070)
#> 9 1 existing existing POINT (431190 5340870)
#> 10 1 existing existing POINT (437890 5341210)
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: 431110 ymin: 5337710 xmax: 438470 ymax: 5343230
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#> strata type geometry
#> x 1 new POINT (436350 5338410)
#> x1 1 new POINT (434010 5340990)
#> x2 1 new POINT (434630 5338870)
#> x3 1 new POINT (435970 5339490)
#> x4 1 new POINT (437270 5338030)
#> x5 1 new POINT (434150 5339090)
#> x6 1 new POINT (434850 5341650)
#> x7 1 new POINT (433270 5341550)
#> x8 1 new POINT (438210 5338670)
#> x9 1 new POINT (433770 5340570)
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 45 features and 1 field
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 431367.8 ymin: 5337763 xmax: 438545.4 ymax: 5343233
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#> strata geometry
#> 1 1 POINT (437570.5 5343016)
#> 2 1 POINT (434571.1 5342955)
#> 3 1 POINT (434591.5 5341955)
#> 4 1 POINT (433612.2 5340935)
#> 5 1 POINT (436632 5339996)
#> 6 1 POINT (434632.4 5339955)
#> 7 1 POINT (437652.2 5339017)
#> 8 1 POINT (435652.6 5338976)
#> 9 1 POINT (436672.9 5337997)
#> 10 2 POINT (435986.2 5337763)
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 1147 features and 1 field
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 431141.8 ymin: 5337707 xmax: 438544.1 ymax: 5343218
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#> strata geometry
#> 1 1 POINT (438497.4 5337896)
#> 2 1 POINT (438497.4 5337896)
#> 3 1 POINT (438472 5338184)
#> 4 1 POINT (438472 5338184)
#> 5 1 POINT (438497.4 5337896)
#> 6 1 POINT (437973.9 5338140)
#> 7 1 POINT (438210.2 5338305)
#> 8 1 POINT (438472 5338184)
#> 9 1 POINT (438472 5338184)
#> 10 1 POINT (438210.2 5338305)
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/Rtmp3vajEL/Rinst12f525c175ea/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 174 features and 1 field
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 431130.8 ymin: 5337702 xmax: 438544.7 ymax: 5343225
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#> strata geometry
#> 1 1 POINT (431256.8 5343150)
#> 2 1 POINT (431130.8 5342690)
#> 3 1 POINT (431763.6 5342500)
#> 4 1 POINT (432126.7 5343202)
#> 5 1 POINT (432825.1 5343225)
#> 6 1 POINT (431258.5 5340671)
#> 7 1 POINT (432014.1 5342191)
#> 8 1 POINT (432681.2 5342972)
#> 9 1 POINT (431215.6 5340244)
#> 10 1 POINT (432133.4 5341747)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: 5338110 xmax: 438510 ymax: 5343210
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#> zq90 pzabove2 zsd kcenter geometry
#> 66397 17.80 93.3 3.44 1 POINT (431150 5339670)
#> 37774 17.70 59.7 5.12 2 POINT (433110 5341210)
#> 9113 10.10 64.9 2.57 3 POINT (434310 5342750)
#> 32927 6.83 13.4 1.80 4 POINT (433150 5341470)
#> 23870 14.60 88.4 3.51 5 POINT (438510 5341970)
#> 44432 16.90 87.5 4.22 6 POINT (431990 5340850)
#> 77781 15.60 22.0 4.68 7 POINT (435030 5339070)
#> 744 23.50 90.5 6.75 8 POINT (438510 5343210)
#> 16935 15.50 94.8 2.71 9 POINT (434090 5342330)
#> 859 6.19 60.5 1.45 10 POINT (433350 5343190)
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: 5337730 xmax: 438530 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 (431970 5343230)
#> 2 POINT (434530 5343210)
#> 3 POINT (432210 5343190)
#> 4 POINT (433610 5343190)
#> 5 POINT (433670 5343190)
#> 6 POINT (431410 5343170)
#> 7 POINT (434250 5343090)
#> 8 POINT (438450 5343090)
#> 9 POINT (434110 5343050)
#> 10 POINT (432630 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: 431310 ymin: 5337750 xmax: 438370 ymax: 5343110
#> 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 (431870 5343110)
#> 2 POINT (435450 5343110)
#> 3 POINT (436710 5343030)
#> 4 POINT (434430 5342990)
#> 5 POINT (435430 5342930)
#> 6 POINT (435290 5342910)
#> 7 POINT (436030 5342890)
#> 8 POINT (436110 5342890)
#> 9 POINT (434470 5342810)
#> 10 POINT (433030 5342770)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 316 features and 7 fields
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 431130 ymin: 5337790 xmax: 438550 ymax: 5343230
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#> type.x zq90 pzabove2 zsd strata type.y rule geometry
#> 1 existing 6.92 35.7 1.65 1 new rule1 POINT (435990 5339770)
#> 2 existing 3.31 25.0 0.61 1 new rule1 POINT (434310 5341470)
#> 3 existing 4.68 18.4 1.32 1 new rule1 POINT (433430 5341270)
#> 4 existing 6.90 75.1 1.53 1 new rule1 POINT (436990 5338010)
#> 5 existing 7.08 67.4 1.61 1 new rule1 POINT (437530 5338050)
#> 6 existing 6.50 58.9 1.56 1 new rule1 POINT (436070 5342310)
#> 7 existing 3.55 25.1 0.67 1 new rule1 POINT (434370 5340890)
#> 8 existing 3.78 34.7 0.76 1 new rule1 POINT (435250 5342070)
#> 9 existing 6.79 92.1 1.32 1 new rule1 POINT (431190 5340870)
#> 10 existing 8.30 93.2 1.54 1 new rule1 POINT (437890 5341210)
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: 431130 ymin: 5337710 xmax: 438530 ymax: 5343230
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#> type.x zq90 pzabove2 zsd strata type.y rule geometry
#> 1 existing 6.92 35.7 1.65 1 new rule1 POINT (435990 5339770)
#> 2 existing 3.31 25.0 0.61 1 new rule1 POINT (434310 5341470)
#> 3 existing 4.68 18.4 1.32 1 new rule1 POINT (433430 5341270)
#> 4 existing 6.90 75.1 1.53 1 new rule1 POINT (436990 5338010)
#> 5 existing 7.08 67.4 1.61 1 new rule1 POINT (437530 5338050)
#> 6 existing 6.50 58.9 1.56 1 new rule1 POINT (436070 5342310)
#> 7 existing 3.55 25.1 0.67 1 new rule1 POINT (434370 5340890)
#> 8 existing 3.78 34.7 0.76 1 new rule1 POINT (435250 5342070)
#> 9 existing 6.79 92.1 1.32 1 new rule1 POINT (431190 5340870)
#> 10 existing 8.30 93.2 1.54 1 new rule1 POINT (437890 5341210)
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: 431124.5 ymin: 5337700 xmax: 438545.2 ymax: 5343237
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#> zq90 pzabove2 zsd geometry
#> 166 17.60 98.5 4.17 POINT (436998.9 5341857)
#> 474 9.17 14.3 2.55 POINT (434075.2 5342736)
#> 655 9.89 33.2 2.76 POINT (432876.3 5341796)
#> 240 8.04 92.8 1.81 POINT (437099.3 5338366)
#> 500 11.90 65.5 3.39 POINT (433881.9 5342684)
#> 720 20.90 85.7 5.13 POINT (432964.4 5339129)
#> 890 16.70 94.4 3.18 POINT (431315.3 5339105)
#> 775 13.40 80.2 3.55 POINT (432680.6 5338640)
#> 512 14.00 30.0 3.72 POINT (434510.7 5339540)
#> 200 9.36 40.8 2.63 POINT (437485.9 5338469)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: 431124.5 ymin: 5337700 xmax: 438555.1 ymax: 5343235
#> 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
#> 91482 8.90 90.1 2.00 POINT (436661.3 5338457)
#> 91955 14.90 90.8 3.35 POINT (432205.9 5341204)
#> 91250 8.60 92.5 1.69 POINT (437977.6 5341290)
#> 91886 15.00 88.8 3.64 POINT (433209.1 5338987)
#> 91590 5.79 48.2 1.37 POINT (434860.5 5342117)
#> 91480 6.91 68.6 1.57 POINT (436764.1 5338070)
#> 91291 2.88 21.3 0.66 POINT (438310.4 5338481)
#> 91879 12.60 56.6 3.09 POINT (432374.7 5342905)
#> 92079 6.58 84.6 1.42 POINT (431149 5340509)
#> 91378 22.60 90.3 6.48 POINT (437216.7 5340260)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: 431215 ymin: 5337710 xmax: 438479.2 ymax: 5343240
#> 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
#> 91928 18.90 89.9 4.50 70.08395 POINT (432296.4 5341642)
#> 91426 12.50 90.5 3.01 185.62433 POINT (436419.1 5341703)
#> 91920 20.10 93.2 3.88 46.05984 POINT (432707.5 5340096)
#> 91604 21.00 86.4 6.63 235.92496 POINT (435283.8 5339746)
#> 91635 3.37 19.4 0.63 27.47076 POINT (434679.5 5341241)
#> 91929 18.70 69.5 3.82 127.35095 POINT (432245.1 5341835)
#> 91771 8.73 52.5 2.37 122.25643 POINT (433661.7 5341177)
#> 91545 13.80 83.1 3.70 482.14827 POINT (435401.3 5341640)
#> 91630 13.70 47.6 3.44 51.61126 POINT (435039.2 5339888)
#> 92069 19.70 93.9 4.74 22.72837 POINT (431868.3 5337803)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: 431239.5 ymin: 5337735 xmax: 438542.8 ymax: 5343240
#> 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
#> 91501 12.20 75.3 3.47 84.92854 POINT (434471.6 5338909)
#> 91295 18.10 79.5 4.14 61.87884 POINT (436857 5341613)
#> 91658 15.80 97.0 2.51 83.52699 POINT (431535.5 5340612)
#> 91223 9.43 88.0 1.96 151.02703 POINT (438080.4 5340903)
#> 91659 15.60 67.2 5.30 78.11264 POINT (431484.1 5340805)
#> 91433 20.00 50.6 5.55 213.71056 POINT (434987.8 5340081)
#> 91234 18.50 94.6 3.17 118.09580 POINT (438503.7 5338532)
#> 91369 5.73 62.4 1.34 122.41092 POINT (435286.3 5342851)
#> 91304 13.80 89.0 3.38 116.51806 POINT (436355.5 5342721)
#> 91492 18.30 75.8 5.63 53.15844 POINT (433637.2 5342826)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: 431122 ymin: 5337700 xmax: 438542.8 ymax: 5343228
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#> zq90 pzabove2 zsd geometry
#> 4 14.9 87.5 3.53 POINT (438442.5 5342655)
#> 5 19.6 85.0 4.33 POINT (438391.1 5342848)
#> 6 14.4 69.9 4.00 POINT (438339.7 5343042)
#> 9 25.2 85.2 7.38 POINT (438506.1 5341637)
#> 15 17.0 89.9 3.74 POINT (438197.8 5342797)
#> 16 12.4 87.5 2.81 POINT (438146.4 5342990)
#> 17 16.2 89.2 4.28 POINT (438095.1 5343184)
#> 19 17.6 87.6 4.43 POINT (438467 5341006)
#> 26 14.8 81.9 3.54 POINT (438004.5 5342746)
#> 27 6.0 13.9 1.48 POINT (437953.1 5342939)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: 431149 ymin: 5337710 xmax: 438542.8 ymax: 5343228
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#> zq90 pzabove2 zsd geometry
#> 4 14.9 87.5 3.53 POINT (438442.5 5342655)
#> 9 25.2 85.2 7.38 POINT (438506.1 5341637)
#> 10 15.3 97.0 3.29 POINT (438454.7 5341831)
#> 16 12.4 87.5 2.81 POINT (438146.4 5342990)
#> 18 19.8 92.5 5.62 POINT (438518.3 5340813)
#> 22 15.1 93.2 2.93 POINT (438210.1 5341972)
#> 27 6.0 13.9 1.48 POINT (437953.1 5342939)
#> 29 18.2 89.5 4.21 POINT (438530.6 5339988)
#> 31 16.9 60.1 5.09 POINT (438427.8 5340375)
#> 32 17.4 87.3 4.93 POINT (438325.1 5340761)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: 431109.8 ymin: 5337708 xmax: 438515.9 ymax: 5343228
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#> zq90 pzabove2 zsd geometry
#> 1 14.70 65.599998 4.02 POINT (435347.5 5338728)
#> 2 14.30 88.900002 2.82 POINT (437101.7 5341471)
#> 3 17.30 69.500000 4.58 POINT (432489.7 5341693)
#> 4 20.80 9.900001 5.62 POINT (434652.6 5339785)
#> 5 22.30 88.300003 7.45 POINT (437745.2 5340607)
#> 6 17.10 96.599998 3.17 POINT (435993.4 5340969)
#> 7 9.99 59.000000 2.81 POINT (437047.9 5338559)
#> 8 3.40 16.600000 0.66 POINT (435530.9 5342709)
#> 9 14.40 64.500000 3.82 POINT (437307.2 5340698)
#> 10 20.60 95.700005 4.77 POINT (437140.9 5342102)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 299 features and 4 fields
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 431109.8 ymin: 5337708 xmax: 438518.3 ymax: 5343225
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#> strata zq90 pzabove2 zsd geometry
#> 1 2 18.6 91.2 3.29 POINT (431768 5341295)
#> 2 2 17.9 91.9 3.52 POINT (434177.9 5342349)
#> 3 2 14.3 64.9 4.67 POINT (436159.8 5339565)
#> 4 2 18.1 79.5 4.14 POINT (436857 5341613)
#> 5 2 18.6 87.3 4.54 POINT (435942 5341163)
#> 6 2 17.0 92.9 3.92 POINT (433725.3 5340159)
#> 7 2 21.4 89.6 4.16 POINT (432553.3 5340676)
#> 8 2 16.2 93.6 3.28 POINT (432692.8 5337815)
#> 9 2 17.8 92.9 3.67 POINT (437165.3 5340453)
#> 10 2 18.2 87.4 4.15 POINT (437050.3 5341664)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: 431109.8 ymin: 5337708 xmax: 438555.1 ymax: 5343235
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#> strata zq90 pzabove2 zsd geometry
#> 1 2 15.3 96.0 3.33 POINT (433659.3 5338072)
#> 2 2 18.1 79.5 4.14 POINT (436857 5341613)
#> 3 2 17.6 90.7 3.80 POINT (432127.6 5339942)
#> 4 2 16.2 94.2 3.03 POINT (431134.3 5338229)
#> 5 2 18.9 94.6 4.07 POINT (433776.7 5339966)
#> 6 2 16.6 88.9 3.87 POINT (433918.6 5340211)
#> 7 2 15.0 95.7 3.77 POINT (436057 5339951)
#> 8 2 19.4 90.0 4.46 POINT (435349.9 5341833)
#> 9 2 17.0 93.6 2.99 POINT (432462.8 5340238)
#> 10 2 15.7 95.9 2.70 POINT (434549.8 5340172)#--- 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 99 features and 4 fields
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 431124.5 ymin: 5337803 xmax: 438555.1 ymax: 5343186
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#> strata zq90 pzabove2 zsd geometry
#> 1 2 16.3 97.9 3.54 POINT (437319.5 5339873)
#> 2 2 14.4 94.7 3.34 POINT (435917.5 5342812)
#> 3 2 15.3 95.6 2.47 POINT (435746.3 5338006)
#> 4 2 16.2 86.9 4.01 POINT (433248.2 5339619)
#> 5 2 15.5 93.0 3.76 POINT (431469.5 5338525)
#> 6 2 15.9 74.1 3.63 POINT (437681.6 5341625)
#> 7 2 14.9 83.2 3.57 POINT (431317.8 5342210)
#> 8 2 14.6 82.6 4.00 POINT (435863.7 5339900)
#> 9 2 14.6 95.8 3.04 POINT (434229.3 5342156)
#> 10 2 18.6 95.5 3.10 POINT (434574.3 5338523)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).