# Sampling

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_srs

We 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: 431110 ymin: 5337710 xmax: 438550 ymax: 5343230
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#>                  geometry
#> 1  POINT (433090 5341010)
#> 2  POINT (431330 5338570)
#> 3  POINT (432850 5341510)
#> 4  POINT (435910 5340830)
#> 5  POINT (433450 5338670)
#> 6  POINT (435790 5339510)
#> 7  POINT (434630 5342470)
#> 8  POINT (434990 5342310)
#> 9  POINT (435890 5337710)
#> 10 POINT (436370 5342510)
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: 5337770 xmax: 438470 ymax: 5343230
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#>                  geometry
#> 1  POINT (438010 5339830)
#> 2  POINT (438290 5338230)
#> 3  POINT (437190 5341690)
#> 4  POINT (438150 5338810)
#> 5  POINT (431190 5342790)
#> 6  POINT (438010 5339370)
#> 7  POINT (431970 5338410)
#> 8  POINT (432410 5340890)
#> 9  POINT (434110 5340690)
#> 10 POINT (436930 5341770)

## sample_systematic

The 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 38 features and 0 fields
#> Geometry type: POINT
#> Dimension:     XY
#> Bounding box:  xmin: 431305.9 ymin: 5337752 xmax: 438525.8 ymax: 5342882
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#>                    geometry
#> 1  POINT (438525.8 5340127)
#> 2  POINT (438129.9 5341046)
#> 3    POINT (437734 5341964)
#> 4  POINT (437338.2 5342882)
#> 5  POINT (438399.3 5337895)
#> 6  POINT (438003.4 5338813)
#> 7  POINT (437607.5 5339731)
#> 8  POINT (437211.6 5340650)
#> 9  POINT (436815.7 5341568)
#> 10 POINT (436419.9 5342486)
#--- 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 170 features and 0 fields
#> Geometry type: POINT
#> Dimension:     XY
#> Bounding box:  xmin: 431109.3 ymin: 5337707 xmax: 438552 ymax: 5343194
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#>                    geometry
#> 1  POINT (431109.3 5338570)
#> 2  POINT (431281.8 5339533)
#> 3  POINT (431122.4 5343089)
#> 4  POINT (431282.5 5338189)
#> 5  POINT (431250.4 5339209)
#> 6  POINT (431167.5 5340129)
#> 7  POINT (431381.7 5341077)
#> 8  POINT (431319.4 5341729)
#> 9  POINT (431144.3 5342728)
#> 10 POINT (431858.4 5337844)
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 614 features and 0 fields
#> Geometry type: POINT
#> Dimension:     XY
#> Bounding box:  xmin: 431155 ymin: 5337723 xmax: 438551.6 ymax: 5343235
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#>                    geometry
#> 1  POINT (438551.6 5337723)
#> 2  POINT (438484.8 5338761)
#> 3  POINT (438551.6 5337723)
#> 4  POINT (438331.2 5337909)
#> 5  POINT (438382.4 5338193)
#> 6  POINT (438315.6 5339232)
#> 7  POINT (438484.8 5338761)
#> 8  POINT (438382.4 5338193)
#> 9    POINT (438162 5338380)
#> 10 POINT (438213.2 5338664)

## sample_strat

The 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: 431230 ymin: 5337730 xmax: 438530 ymax: 5343210
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#>    strata type  rule               geometry
#> x       1  new rule1 POINT (435970 5339710)
#> x1      1  new rule1 POINT (433370 5340910)
#> x2      1  new rule1 POINT (431410 5340790)
#> x3      1  new rule1 POINT (435870 5339470)
#> x4      1  new rule1 POINT (434390 5341070)
#> x5      1  new rule1 POINT (435910 5339530)
#> x6      1  new rule1 POINT (433890 5341310)
#> x7      1  new rule1 POINT (434410 5341450)
#> x8      1  new rule1 POINT (433350 5341370)
#> x9      1  new rule1 POINT (434050 5340650)

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 to

TIP!

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: 5343210
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#>    strata     type     rule               geometry
#> 1       1 existing existing POINT (434870 5341510)
#> 2       1 existing existing POINT (433050 5341850)
#> 3       1 existing existing POINT (438250 5340950)
#> 4       1 existing existing POINT (433470 5340850)
#> 5       1 existing existing POINT (434370 5342150)
#> 6       1 existing existing POINT (434550 5339610)
#> 7       1 existing existing POINT (433230 5341170)
#> 8       1 existing existing POINT (434050 5343170)
#> 9       1 existing existing POINT (433750 5340930)
#> 10      1 existing existing POINT (432910 5343210)

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: 431170 ymin: 5337730 xmax: 438530 ymax: 5343210
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#>    strata     type     rule               geometry
#> 1       1 existing existing POINT (434870 5341510)
#> 2       1 existing existing POINT (433050 5341850)
#> 3       1 existing existing POINT (438250 5340950)
#> 4       1 existing existing POINT (433470 5340850)
#> 5       1 existing existing POINT (434370 5342150)
#> 6       1 existing existing POINT (434550 5339610)
#> 7       1 existing existing POINT (433230 5341170)
#> 8       1 existing existing POINT (434050 5343170)
#> 9       1 existing existing POINT (433750 5340930)
#> 10      1 existing existing POINT (432910 5343210)

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 = "random

Stratified 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: 5337750 xmax: 438550 ymax: 5343090
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#>    strata type               geometry
#> x       1  new POINT (432610 5342450)
#> x1      1  new POINT (433810 5342730)
#> x2      1  new POINT (436950 5338190)
#> x3      1  new POINT (434410 5341670)
#> x4      1  new POINT (434070 5341010)
#> x5      1  new POINT (437190 5338110)
#> x6      1  new POINT (432550 5339390)
#> x7      1  new POINT (434550 5342850)
#> x8      1  new POINT (438510 5339610)
#> x9      1  new POINT (438550 5340210)

## sample_sys_strat

sample_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
)
#> Processing strata : 1
#> Processing strata : 2
#> Processing strata : 3
#> Processing strata : 4
#> Warning: [extract] source already open for reading #> Simple feature collection with 40 features and 1 field
#> Geometry type: POINT
#> Dimension:     XY
#> Bounding box:  xmin: 431117.1 ymin: 5337763 xmax: 437960.4 ymax: 5343168
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#>    strata                 geometry
#> 1       1 POINT (434494.7 5342773)
#> 2       1 POINT (433322.7 5341152)
#> 3       1   POINT (435305 5342187)
#> 4       1   POINT (434719 5341376)
#> 5       1 POINT (434133.1 5340566)
#> 6       1 POINT (434357.4 5339170)
#> 7       1 POINT (435753.7 5339394)
#> 8       1   POINT (437150 5339619)
#> 9       1 POINT (435978.1 5337998)
#> 10      1 POINT (437960.4 5339033)

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
#> Processing strata : 2
#> Processing strata : 3
#> Processing strata : 4
#> Warning: [extract] source already open for reading #> Simple feature collection with 1069 features and 1 field
#> Geometry type: POINT
#> Dimension:     XY
#> Bounding box:  xmin: 431126.2 ymin: 5337700 xmax: 438538.4 ymax: 5343230
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#>    strata                 geometry
#> 1       1 POINT (437892.8 5343082)
#> 2       1 POINT (437892.8 5343082)
#> 3       1 POINT (437611.5 5343017)
#> 4       1 POINT (437611.5 5343017)
#> 5       1 POINT (437892.8 5343082)
#> 6       1 POINT (437723.9 5342530)
#> 7       1   POINT (437527 5342741)
#> 8       1 POINT (437611.5 5343017)
#> 9       1 POINT (438314.4 5341897)
#> 10      1 POINT (437611.5 5343017)

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")
#> Reading layer inventory_polygons' from data source
#>   C:\Users\tgood\AppData\Local\Temp\Rtmp2xwKSP\Rinst2aa0542e2ac0\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
#> Processing strata : 2
#> Processing strata : 3
#> Simple feature collection with 166 features and 1 field
#> Geometry type: POINT
#> Dimension:     XY
#> Bounding box:  xmin: 431153.5 ymin: 5337796 xmax: 438484.2 ymax: 5343205
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#>    strata                 geometry
#> 1       1 POINT (434271.2 5337837)
#> 2       1 POINT (433049.7 5338595)
#> 3       1 POINT (432287.7 5339171)
#> 4       1   POINT (432139 5339388)
#> 5       1 POINT (434878.2 5338086)
#> 6       1 POINT (432658.2 5339587)
#> 7       1 POINT (431179.5 5340146)
#> 8       1 POINT (435299.6 5338195)
#> 9       1 POINT (434810.3 5338638)
#> 10      1 POINT (432527.7 5339956) ## sample_nc

sample_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: 431550 ymin: 5338070 xmax: 438450 ymax: 5343030
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#>        zq90 pzabove2  zsd kcenter               geometry
#> 95856  3.08      7.2 0.58       1 POINT (438450 5338110)
#> 21241 17.90     88.7 4.39       2 POINT (438150 5342110)
#> 57393 26.50     85.7 8.38       3 POINT (437570 5340170)
#> 65141 12.60     52.5 3.45       4 POINT (435870 5339750)
#> 46231 11.50     89.0 2.66       5 POINT (438130 5340770)
#> 79644 19.90     19.1 6.50       6 POINT (434990 5338970)
#> 96523  8.01     85.5 1.78       7 POINT (436870 5338070)
#> 54404 23.70     89.1 6.85       8 POINT (437470 5340330)
#> 3753  18.50     85.0 5.19       9 POINT (431550 5343030)
#> 43748 16.30     71.3 4.39      10 POINT (433230 5340890)

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. #--- total samples = nSamp * k (25 * 2) = 50 ---#
nrow(samples)
#>  50

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$kplot ## sample_clhs

sample_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 iterations The 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
) # plot
#>
|---------|---------|---------|---------|
========================================= sample_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
) # plot ## sample_balanced

The sample_balanced() algorithm performs a balanced sampling methodology from the stratifyR / SamplingBigData packages.

sample_balanced(
mraster = mraster, # input
nSamp = 200, # desired sample size
plot = TRUE
) # plot #> Simple feature collection with 200 features and 0 fields
#> Geometry type: POINT
#> Dimension:     XY
#> Bounding box:  xmin: 431190 ymin: 5337710 xmax: 438410 ymax: 5343230
#> Projected CRS: +proj=utm +zone=17 +ellps=GRS80 +units=m +no_defs
#> First 10 features:
#>                  geometry
#> 1  POINT (434510 5343230)
#> 2  POINT (435270 5343210)
#> 3  POINT (437310 5343190)
#> 4  POINT (435170 5343170)
#> 5  POINT (434110 5343110)
#> 6  POINT (435790 5343110)
#> 7  POINT (431850 5343070)
#> 8  POINT (433830 5343070)
#> 9  POINT (435630 5343070)
#> 10 POINT (435190 5343050)
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: 431290 ymin: 5337770 xmax: 438550 ymax: 5343210
#> Projected CRS: +proj=utm +zone=17 +ellps=GRS80 +units=m +no_defs
#> First 10 features:
#>                  geometry
#> 1  POINT (437130 5341590)
#> 2  POINT (431290 5342650)
#> 3  POINT (435470 5338690)
#> 4  POINT (434370 5339910)
#> 5  POINT (434150 5338550)
#> 6  POINT (438070 5340730)
#> 7  POINT (434690 5338690)
#> 8  POINT (433150 5341770)
#> 9  POINT (434070 5342530)
#> 10 POINT (432610 5341070)

## sample_ahels

The 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:

1. Determines the quantile distributions of existing sample units and mraster covariates.

2. Determines quantiles where there is a disparity between sample units and covariates.

3. 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 303 features and 7 fields
#> Geometry type: POINT
#> Dimension:     XY
#> Bounding box:  xmin: 431170 ymin: 5337710 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 4.66     63.8 1.04      1    new rule1 POINT (434870 5341510)
#> 2  existing 9.80     13.3 2.81      1    new rule1 POINT (433050 5341850)
#> 3  existing 8.34     61.4 1.84      1    new rule1 POINT (438250 5340950)
#> 4  existing 3.04     40.2 0.50      1    new rule1 POINT (433470 5340850)
#> 5  existing 7.08     23.0 2.29      1    new rule1 POINT (434370 5342150)
#> 6  existing 2.95      1.5 0.56      1    new rule1 POINT (434550 5339610)
#> 7  existing 5.99     34.4 1.42      1    new rule1 POINT (433230 5341170)
#> 8  existing 6.46     72.1 1.29      1    new rule1 POINT (434050 5343170)
#> 9  existing 2.51      5.7 0.37      1    new rule1 POINT (433750 5340930)
#> 10 existing 5.54     54.7 1.15      1    new rule1 POINT (432910 5343210)

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: 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 4.66     63.8 1.04      1    new rule1 POINT (434870 5341510)
#> 2  existing 9.80     13.3 2.81      1    new rule1 POINT (433050 5341850)
#> 3  existing 8.34     61.4 1.84      1    new rule1 POINT (438250 5340950)
#> 4  existing 3.04     40.2 0.50      1    new rule1 POINT (433470 5340850)
#> 5  existing 7.08     23.0 2.29      1    new rule1 POINT (434370 5342150)
#> 6  existing 2.95      1.5 0.56      1    new rule1 POINT (434550 5339610)
#> 7  existing 5.99     34.4 1.42      1    new rule1 POINT (433230 5341170)
#> 8  existing 6.46     72.1 1.29      1    new rule1 POINT (434050 5343170)
#> 9  existing 2.51      5.7 0.37      1    new rule1 POINT (433750 5340930)
#> 10 existing 5.54     54.7 1.15      1    new rule1 POINT (432910 5343210)

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_existing

Acknowledging 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) #--- sub sample using ---#
e <- existing %>%
extract_metrics(mraster = mraster, existing = .)

### sample_existing(type = "clhs")

The algorithm is unique in that it has two fundamental approaches:

1. Sample exclusively using 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: 431120.4 ymin: 5337724 xmax: 438554.5 ymax: 5343230
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#>      zq90 pzabove2  zsd                 geometry
#> 616 16.40     47.8 5.16 POINT (435185.9 5339238)
#> 501 12.90      5.1 4.46 POINT (438052.6 5338169)
#> 121  9.76     76.1 2.70 POINT (435744.3 5342420)
#> 722  6.61     74.2 1.57 POINT (431468.8 5340833)
#> 628 14.60     76.0 3.34 POINT (433145.1 5340501)
#> 815 13.70     74.8 3.82 POINT (432578.4 5339205)
#> 167  2.13      0.5 0.30   POINT (436044 5341764)
#> 783 18.40     95.3 3.54 POINT (434554.3 5338217)
#> 700  8.82     24.9 2.44 POINT (435720.4 5338201)
#> 408 11.10     57.1 3.43 POINT (433606.6 5341627)
1. Sub-sampling using raster distributions

Our 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: 431153.1 ymin: 5337723 xmax: 438554.5 ymax: 5343198
#> Projected CRS: +proj=utm +zone=17 +ellps=GRS80 +units=m +no_defs
#> First 10 features:
#>        zq90 pzabove2  zsd                 geometry
#> 91302  8.29     79.9 1.82 POINT (438125.2 5340947)
#> 91871  2.14      0.4 0.25 POINT (435145.4 5338792)
#> 91290 11.70     75.6 2.98 POINT (436359.7 5342275)
#> 91306 14.60     82.7 4.02 POINT (437444.9 5341368)
#> 91863  7.94     90.0 1.63   POINT (436846 5337740)
#> 91323 16.90     79.9 4.58 POINT (434553.9 5343157)
#> 91592 22.20     92.2 5.65 POINT (435817.4 5340258)
#> 91918 19.10     86.5 5.43 POINT (431298.8 5340938)
#> 92064 17.40     81.6 4.87 POINT (432157.4 5338525)
#> 91528 13.30     63.5 3.19 POINT (433306.9 5342282)

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: 431153.1 ymin: 5337724 xmax: 438514 ymax: 5343230
#> Projected CRS: +proj=utm +zone=17 +ellps=GRS80 +units=m +no_defs
#> First 10 features:
#>        zq90 pzabove2  zsd dist2access                 geometry
#> 91629 13.20     80.9 3.65   175.86566 POINT (436052.3 5339878)
#> 91854 16.10     97.2 3.02   137.71952 POINT (432869.8 5340436)
#> 91815 10.90      9.2 3.70    62.99112 POINT (434505.6 5339659)
#> 91272  6.88     52.8 1.72    94.30411 POINT (436124.9 5342655)
#> 91806  7.55     90.1 1.58    83.10515 POINT (436886.5 5338185)
#> 91828 18.80     85.9 4.70   162.46812 POINT (432294.8 5341027)
#> 92010 13.70     74.8 3.82   178.58861 POINT (432578.4 5339205)
#> 91805  7.06     65.5 1.62   146.17040 POINT (437056.6 5338080)
#> 91558  4.81     29.6 1.08   124.93850 POINT (434562.1 5341270)
#> 91671 17.20     58.1 3.97    15.93475 POINT (435266.8 5340129)

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: 431153.1 ymin: 5337764 xmax: 438538.4 ymax: 5343230
#> Projected CRS: +proj=utm +zone=17 +ellps=GRS80 +units=m +no_defs
#> First 10 features:
#>        zq90 pzabove2  zsd dist2access                 geometry
#> 91265  8.97     53.6 2.27   127.58001 POINT (435064.1 5342841)
#> 91425 14.00     27.0 3.72   150.51974 POINT (434181.6 5341035)
#> 91288  5.74     29.1 1.41    80.86828 POINT (435363.7 5342185)
#> 91518 24.30     88.4 7.00   128.78760 POINT (434440.8 5339934)
#> 91329 11.80     72.7 3.35   126.99044 POINT (434537.8 5341991)
#> 91534 14.90     85.7 4.13    86.88579 POINT (434845.7 5339448)
#> 91227 15.10     70.6 4.79   145.87087 POINT (435719.9 5343141)
#> 91466 20.70     91.6 3.65   130.38649 POINT (436181.9 5339327)
#> 91582 15.50     84.3 4.44    90.19507 POINT (432319.2 5340306)
#> 91309 19.60     95.4 5.18   140.70066 POINT (438214.4 5339951)

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: 431128.7 ymin: 5337715 xmax: 438554.5 ymax: 5343214
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#>     zq90 pzabove2  zsd                 geometry
#> 3  17.90     83.0 5.72 POINT (438392.2 5342898)
#> 8  16.10     85.8 5.10   POINT (438287 5342728)
#> 9  16.50     89.9 3.79 POINT (438116.9 5342834)
#> 16  3.26      1.0 0.60 POINT (437841.6 5342769)
#> 17  2.61      8.8 0.41 POINT (437671.5 5342874)
#> 19 22.90     82.2 7.23 POINT (437331.4 5343084)
#> 22 14.80     90.7 2.97 POINT (438246.5 5342283)
#> 28 11.10     54.0 3.29 POINT (437226.1 5342914)
#> 31 13.30     78.4 3.22 POINT (438311.3 5342008)
#> 32 17.90     88.7 4.39 POINT (438141.3 5342113)
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: 431161.4 ymin: 5337764 xmax: 438498 ymax: 5343198
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#>      zq90 pzabove2  zsd                 geometry
#> 459 19.40     90.5 5.72 POINT (431460.6 5342720)
#> 3   17.90     83.0 5.72 POINT (438392.2 5342898)
#> 354  8.77     71.2 2.19 POINT (436602.9 5340007)
#> 575  8.21     88.9 1.75 POINT (437331.9 5338145)
#> 615 16.20     17.2 5.24 POINT (435355.9 5339133)
#> 179 20.10     73.9 5.84 POINT (433833.2 5343133)
#> 167  2.13      0.5 0.30   POINT (436044 5341764)
#> 578 12.10     71.9 3.56 POINT (436821.7 5338461)
#> 325 13.80     96.2 2.97 POINT (434667.4 5341440)
#> 716 17.40     89.1 4.49 POINT (432489.2 5340201)

### 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: 431120.4 ymin: 5337715 xmax: 438514 ymax: 5343238
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#>    zq90 pzabove2  zsd                 geometry
#> 1  16.2     88.4 4.01 POINT (438368.3 5338679)
#> 2  15.7     87.4 4.34 POINT (431242.2 5339327)
#> 3  14.3     79.0 3.97 POINT (435890.5 5338096)
#> 4  18.4     89.1 4.28 POINT (433209.9 5340226)
#> 5  29.2     91.6 8.09 POINT (437380.1 5341643)
#> 6  19.8     86.8 5.82 POINT (438400.5 5341012)
#> 7  19.4     92.0 6.01   POINT (431712 5338565)
#> 8  12.7     95.8 2.87 POINT (435703.9 5341975)
#> 9  18.3     86.5 4.50   POINT (432805 5340711)
#> 10 13.1     80.5 2.85 POINT (434619.1 5337942)

### 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 300 features and 4 fields
#> Geometry type: POINT
#> Dimension:     XY
#> Bounding box:  xmin: 431120.9 ymin: 5337732 xmax: 438505.8 ymax: 5343230
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#>    strata zq90 pzabove2      zsd                 geometry
#> 1       4 18.8     81.2 5.050000 POINT (436805.1 5342234)
#> 2       4 22.3     33.8 9.349999   POINT (435372 5340299)
#> 3       4 26.4     85.3 8.080000 POINT (433388.3 5338234)
#> 4       4 18.6     63.0 5.570000 POINT (432845.4 5341157)
#> 5       4 18.1     73.7 5.040000 POINT (438327.4 5343174)
#> 6       4 22.9     82.2 7.230000 POINT (437331.4 5343084)
#> 7       4 21.5     95.6 5.920000 POINT (438230.4 5341117)
#> 8       4 19.9     97.7 5.110000 POINT (431622.8 5339561)
#> 9       4 17.6      8.2 5.510000 POINT (434975.4 5338898)
#> 10      4 20.3      3.0 7.220000   POINT (438344 5339400)

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: 431120.4 ymin: 5337716 xmax: 438554.5 ymax: 5343238
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#>    strata zq90 pzabove2  zsd                 geometry
#> 1       4 18.4     82.2 4.99 POINT (432149.1 5340412)
#> 2       4 18.3     78.0 5.19   POINT (438036 5341943)
#> 3       4 21.2     94.7 5.31   POINT (435105 5338347)
#> 4       4 24.8     89.8 6.59 POINT (433995.4 5339975)
#> 5       4 18.6     63.0 5.57 POINT (432845.4 5341157)
#> 6       4 19.5     80.9 4.97 POINT (435833.5 5341424)
#> 7       4 19.9     97.7 5.11 POINT (431622.8 5339561)
#> 8       4 30.7     93.3 8.71 POINT (437315.3 5341918)
#> 9       4 19.3     92.7 4.99 POINT (435857.8 5340704)
#> 10      4 18.6     82.4 5.07 POINT (433517.4 5342623)
#--- 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:

#--- check proportions match weights ---#
table(s\$strata) / 100
#>
#>   1   2   3   4
#> 0.2 0.6 0.1 0.1

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: 431120.9 ymin: 5337739 xmax: 438538.4 ymax: 5343214
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#>    strata zq90 pzabove2  zsd                 geometry
#> 1       4 22.3     87.4 5.84 POINT (435331.6 5339853)
#> 2       4 20.6     92.0 4.74 POINT (434991.4 5340064)
#> 3       4 18.1     74.9 5.15 POINT (435428.5 5341910)
#> 4       4 17.6      8.2 5.51 POINT (434975.4 5338898)
#> 5       4 23.0     95.0 4.90 POINT (435922.6 5340428)
#> 6       4 23.3     77.8 6.55 POINT (438335.7 5341287)
#> 7       4 18.6     82.4 5.07 POINT (433517.4 5342623)
#> 8       4 19.4     92.0 6.01   POINT (431712 5338565)
#> 9       4 18.8     69.8 5.80 POINT (433015.5 5341052)
#> 10      4 22.4     96.9 5.49   POINT (432959 5339440)

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).