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: 431170 ymin: 5337710 xmax: 438550 ymax: 5343230
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#>                  geometry
#> 1  POINT (433750 5340030)
#> 2  POINT (436230 5342990)
#> 3  POINT (437390 5338450)
#> 4  POINT (431950 5337730)
#> 5  POINT (431910 5340650)
#> 6  POINT (431270 5338650)
#> 7  POINT (438550 5343070)
#> 8  POINT (432570 5340470)
#> 9  POINT (434810 5339150)
#> 10 POINT (436670 5342430)
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: 431130 ymin: 5337730 xmax: 438510 ymax: 5343230
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#>                  geometry
#> 1  POINT (435970 5340090)
#> 2  POINT (432050 5338170)
#> 3  POINT (438110 5342130)
#> 4  POINT (433730 5342470)
#> 5  POINT (435810 5343130)
#> 6  POINT (435550 5340170)
#> 7  POINT (435390 5342850)
#> 8  POINT (435030 5339930)
#> 9  POINT (434350 5338590)
#> 10 POINT (434650 5341030)

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 40 features and 0 fields
#> Geometry type: POINT
#> Dimension:     XY
#> Bounding box:  xmin: 431181.1 ymin: 5337849 xmax: 438556.7 ymax: 5343236
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#>                    geometry
#> 1  POINT (431697.4 5337849)
#> 2  POINT (432692.1 5337953)
#> 3  POINT (433686.7 5338056)
#> 4  POINT (434681.4 5338159)
#> 5  POINT (436670.7 5338366)
#> 6  POINT (437665.3 5338469)
#> 7  POINT (432588.8 5338947)
#> 8  POINT (434578.1 5339154)
#> 9  POINT (435572.8 5339257)
#> 10 POINT (436567.4 5339360)
#--- 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 163 features and 0 fields
#> Geometry type: POINT
#> Dimension:     XY
#> Bounding box:  xmin: 431106.5 ymin: 5337704 xmax: 438558.2 ymax: 5343229
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#>                    geometry
#> 1  POINT (437812.4 5342986)
#> 2  POINT (438511.2 5342620)
#> 3  POINT (437985.1 5342464)
#> 4  POINT (437658.8 5342686)
#> 5  POINT (438197.9 5341949)
#> 6  POINT (437808.3 5342379)
#> 7  POINT (436776.8 5342766)
#> 8  POINT (437254.1 5342242)
#> 9    POINT (436160 5342984)
#> 10 POINT (437489.7 5341841)
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 621 features and 0 fields
#> Geometry type: POINT
#> Dimension:     XY
#> Bounding box:  xmin: 431295.4 ymin: 5337763 xmax: 438369.7 ymax: 5343066
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#>                    geometry
#> 1  POINT (438199.1 5337763)
#> 2  POINT (438345.5 5338012)
#> 3  POINT (438345.5 5338012)
#> 4  POINT (438203.2 5338263)
#> 5  POINT (438349.5 5338512)
#> 6  POINT (438199.1 5337763)
#> 7  POINT (437910.5 5337766)
#> 8  POINT (438199.1 5337763)
#> 9  POINT (438349.5 5338512)
#> 10 POINT (438207.2 5338763)

sample_strat

The sample_strat() contains two methods to perform sampling:

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:

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: 431130 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 (434910 5341610)
#> x1      1  new rule2 POINT (437990 5341190)
#> x2      1  new rule2 POINT (431890 5341390)
#> x3      1  new rule2 POINT (436070 5342630)
#> x4      1  new rule2 POINT (437870 5337970)
#> x5      1  new rule2 POINT (436990 5342970)
#> x6      1  new rule2 POINT (435990 5339470)
#> x7      1  new rule2 POINT (437850 5339070)
#> x8      1  new rule2 POINT (436670 5339270)
#> x9      1  new rule2 POINT (431550 5342570)

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: 431110 ymin: 5337730 xmax: 438550 ymax: 5343230
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#>    strata     type     rule               geometry
#> 1       1 existing existing POINT (434450 5340930)
#> 2       1 existing existing POINT (433930 5341150)
#> 3       1 existing existing POINT (433430 5339910)
#> 4       1 existing existing POINT (437490 5339210)
#> 5       1 existing existing POINT (435890 5339630)
#> 6       1 existing existing POINT (435150 5342490)
#> 7       1 existing existing POINT (434290 5342550)
#> 8       1 existing existing POINT (436570 5337970)
#> 9       1 existing existing POINT (432790 5342830)
#> 10      1 existing existing POINT (437990 5340030)

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: 431110 ymin: 5337770 xmax: 438550 ymax: 5343190
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#>    strata     type     rule               geometry
#> 1       1 existing existing POINT (434450 5340930)
#> 2       1 existing existing POINT (433930 5341150)
#> 3       1 existing existing POINT (433430 5339910)
#> 4       1 existing existing POINT (437490 5339210)
#> 5       1 existing existing POINT (435890 5339630)
#> 6       1 existing existing POINT (435150 5342490)
#> 7       1 existing existing POINT (434290 5342550)
#> 8       1 existing existing POINT (436570 5337970)
#> 9       1 existing existing POINT (432790 5342830)
#> 10      1 existing existing POINT (437990 5340030)

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 1 field
#> Geometry type: POINT
#> Dimension:     XY
#> Bounding box:  xmin: 431110 ymin: 5337710 xmax: 438370 ymax: 5343230
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#>    strata               geometry
#> 1       1 POINT (437530 5343050)
#> 2       1 POINT (432250 5338110)
#> 3       1 POINT (438070 5339150)
#> 4       1 POINT (437530 5338170)
#> 5       1 POINT (433390 5342990)
#> 6       1 POINT (436810 5339390)
#> 7       1 POINT (434170 5340490)
#> 8       1 POINT (434370 5341970)
#> 9       1 POINT (433510 5340750)
#> 10      1 POINT (433150 5340890)

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

#> Simple feature collection with 35 features and 1 field
#> Geometry type: POINT
#> Dimension:     XY
#> Bounding box:  xmin: 431380 ymin: 5337723 xmax: 438398.7 ymax: 5343036
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#>    strata                 geometry
#> 1       1   POINT (433732 5343036)
#> 2       1 POINT (435116.2 5342746)
#> 3       1   POINT (433442 5341651)
#> 4       1 POINT (434826.2 5341361)
#> 5       1 POINT (433989.1 5340814)
#> 6       1 POINT (434536.2 5339977)
#> 7       1 POINT (437594.5 5340781)
#> 8       1 POINT (435920.4 5339687)
#> 9       1 POINT (435083.3 5339140)
#> 10      1 POINT (437851.6 5338560)

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

#> Simple feature collection with 1167 features and 1 field
#> Geometry type: POINT
#> Dimension:     XY
#> Bounding box:  xmin: 431133.8 ymin: 5337703 xmax: 438471.4 ymax: 5343231
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#>    strata                 geometry
#> 1       1 POINT (437909.4 5343215)
#> 2       1 POINT (437909.4 5343215)
#> 3       1 POINT (437777.6 5342958)
#> 4       1 POINT (437909.4 5343215)
#> 5       1 POINT (437909.4 5343215)
#> 6       1 POINT (437777.6 5342958)
#> 7       1 POINT (437489.3 5342943)
#> 8       1 POINT (437802.5 5342458)
#> 9       1 POINT (437489.3 5342943)
#> 10      1 POINT (437777.6 5342958)

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 
#>   `C:\Users\tgood\AppData\Local\Temp\RtmpS4i8tf\Rinst3e0c66941c3a\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
)
#> Assigning a new crs. Use 'project' to transform a SpatRaster to a new crs

#--- 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 173 features and 1 field
#> Geometry type: POINT
#> Dimension:     XY
#> Bounding box:  xmin: 431131.8 ymin: 5337710 xmax: 438505.8 ymax: 5343209
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#>    strata                 geometry
#> 1       1 POINT (431324.7 5343206)
#> 2       1 POINT (432954.6 5343149)
#> 3       1 POINT (433977.5 5343204)
#> 4       1 POINT (431893.3 5342604)
#> 5       1 POINT (432598.4 5342886)
#> 6       1 POINT (433564.6 5343032)
#> 7       1 POINT (434465.4 5342868)
#> 8       1 POINT (431373.1 5342295)
#> 9       1 POINT (433015.7 5342667)
#> 10      1 POINT (433857.3 5342688)

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: 431230 ymin: 5338370 xmax: 438510 ymax: 5343170
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#>        zq90 pzabove2  zsd kcenter               geometry
#> 45598 15.50     87.1 3.81       1 POINT (432930 5340790)
#> 17949 16.30     94.8 2.80       2 POINT (431990 5342270)
#> 50700 11.10     89.3 2.53       3 POINT (437990 5340530)
#> 36188 13.00     73.5 3.33       4 POINT (431230 5341290)
#> 28425  9.93     65.6 2.58       5 POINT (432630 5341710)
#> 40961 22.30     92.6 5.41       6 POINT (437170 5341050)
#> 1306  12.30     50.5 3.40       7 POINT (434830 5343170)
#> 13247 13.60     90.9 3.11       8 POINT (434930 5342530)
#> 90880  8.64     40.4 2.27       9 POINT (435910 5338370)
#> 32927  6.83     13.4 1.80      10 POINT (433150 5341470)

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)
#> [1] 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: 431130 ymin: 5337730 xmax: 438470 ymax: 5343210
#> CRS:           +proj=utm +zone=17 +ellps=GRS80 +units=m +no_defs
#> First 10 features:
#>                  geometry
#> 1  POINT (437910 5343210)
#> 2  POINT (432730 5343170)
#> 3  POINT (437530 5343170)
#> 4  POINT (431570 5343090)
#> 5  POINT (437470 5343090)
#> 6  POINT (431710 5343030)
#> 7  POINT (437890 5342890)
#> 8  POINT (431430 5342870)
#> 9  POINT (435450 5342870)
#> 10 POINT (436870 5342830)
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: 431210 ymin: 5337850 xmax: 438550 ymax: 5343230
#> CRS:           +proj=utm +zone=17 +ellps=GRS80 +units=m +no_defs
#> First 10 features:
#>                  geometry
#> 1  POINT (435650 5342110)
#> 2  POINT (438170 5341990)
#> 3  POINT (433890 5342530)
#> 4  POINT (435050 5338710)
#> 5  POINT (437730 5338990)
#> 6  POINT (436710 5341370)
#> 7  POINT (432630 5342190)
#> 8  POINT (431770 5338070)
#> 9  POINT (432350 5342010)
#> 10 POINT (434790 5338790)

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 251 features and 7 fields
#> Geometry type: POINT
#> Dimension:     XY
#> Bounding box:  xmin: 431110 ymin: 5337770 xmax: 438550 ymax: 5343190
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#>      type.x  zq90 pzabove2  zsd strata type.y  rule               geometry
#> 1  existing  3.40     18.0 0.63      1    new rule1 POINT (434450 5340930)
#> 2  existing  6.21     66.2 1.44      1    new rule2 POINT (433930 5341150)
#> 3  existing  3.56     10.9 0.71      1    new rule2 POINT (433430 5339910)
#> 4  existing  2.73      7.9 0.43      1    new rule2 POINT (437490 5339210)
#> 5  existing  8.41     40.5 2.35      1    new rule2 POINT (435890 5339630)
#> 6  existing  5.82     50.8 1.36      1    new rule2 POINT (435150 5342490)
#> 7  existing  7.46     19.5 2.08      1    new rule2 POINT (434290 5342550)
#> 8  existing  9.38     98.3 1.79      1    new rule2 POINT (436570 5337970)
#> 9  existing 10.10     66.4 2.39      1    new rule2 POINT (432790 5342830)
#> 10 existing  6.05     22.2 1.54      1    new rule2 POINT (437990 5340030)

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  3.40     18.0 0.63      1    new rule1 POINT (434450 5340930)
#> 2  existing  6.21     66.2 1.44      1    new rule2 POINT (433930 5341150)
#> 3  existing  3.56     10.9 0.71      1    new rule2 POINT (433430 5339910)
#> 4  existing  2.73      7.9 0.43      1    new rule2 POINT (437490 5339210)
#> 5  existing  8.41     40.5 2.35      1    new rule2 POINT (435890 5339630)
#> 6  existing  5.82     50.8 1.36      1    new rule2 POINT (435150 5342490)
#> 7  existing  7.46     19.5 2.08      1    new rule2 POINT (434290 5342550)
#> 8  existing  9.38     98.3 1.79      1    new rule2 POINT (436570 5337970)
#> 9  existing 10.10     66.4 2.39      1    new rule2 POINT (432790 5342830)
#> 10 existing  6.05     22.2 1.54      1    new rule2 POINT (437990 5340030)

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 exist 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 at these locations. The sample_existing algorithm provides a method for sub-sampling an existing sample network should the financial / logistical resources not be available to collect data at all sample units. The algorithm leverages latin hypercube sampling using the clhs package to effectively sample within an existing network.

The algorithm has two fundamental approaches:

  1. Sample exclusively using the sample network and the attributes it contains.

  2. Should raster information be available and co-located with the sample, use these data as population values to improve sub-sampling of existing.

Much like the sample_clhs() algorithm, users can define a cost parameter, which will be used to constrain sub-sampling. A cost parameter is a user defined metric/attribute such as distance from roads (e.g. calculate_distance()), elevation, etc.

Basic sub-sampling of existing

First we can create an existing sample for our example. Lets imagine we have a dataset of ~900 samples, and we know we only have resources to sample 300 of them. We have some ALS data available (mraster), which we will use as our distributions to sample within.

#--- generate existing samples and extract metrics ---#
existing <- sample_srs(raster = mraster, nSamp = 900, plot = TRUE)

Now lets sub-sample.

#--- sub sample using ---#
e <- existing %>%
  extract_metrics(mraster = mraster, existing = .)

sample_existing(existing = e, nSamp = 300, plot = TRUE)

#> Simple feature collection with 300 features and 3 fields
#> Geometry type: POINT
#> Dimension:     XY
#> Bounding box:  xmin: 431150 ymin: 5337730 xmax: 438530 ymax: 5343230
#> Projected CRS: UTM Zone 17, Northern Hemisphere
#> First 10 features:
#>      zq90 pzabove2  zsd               geometry
#> 583 23.00     89.1 5.76 POINT (436010 5341190)
#> 55  23.60     91.3 7.09 POINT (438190 5339910)
#> 53  14.00     77.9 3.87 POINT (437030 5340330)
#> 732 12.30     84.1 3.40 POINT (432230 5340750)
#> 570  7.81     67.8 1.91 POINT (434690 5341170)
#> 11   4.87     20.5 1.39 POINT (435970 5342030)
#> 511 13.70     61.9 4.21 POINT (438330 5339110)
#> 495 17.10     79.3 4.63 POINT (433390 5341790)
#> 17  14.60     69.3 4.27 POINT (436290 5342850)
#> 867 19.90     84.3 4.43 POINT (437170 5342130)

TIP!

Notice that we used extract_metrics() after creating our existing. If the user provides a raster for the algorithm this isn’t neccesary (its done internally). If only sample units are given, attributes must be provided and sampling will be conducted on all included attributes.

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

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: 431110 ymin: 5337710 xmax: 438550 ymax: 5343230
#> CRS:           +proj=utm +zone=17 +ellps=GRS80 +units=m +no_defs
#> First 10 features:
#>      zq90 pzabove2  zsd               geometry
#> 203 10.90     96.6 1.61 POINT (435150 5337750)
#> 223 12.70     89.3 2.98 POINT (436910 5343010)
#> 162 15.30     96.5 4.72 POINT (431170 5337830)
#> 850  4.25     41.9 0.87 POINT (434450 5341170)
#> 775 19.00     95.7 4.50 POINT (431490 5338070)
#> 462 15.20     93.5 3.72 POINT (436990 5342190)
#> 669  8.39     41.2 2.26 POINT (437670 5338490)
#> 872  2.68      6.9 0.43 POINT (438470 5338290)
#> 409 11.70     61.4 3.06 POINT (436870 5340190)
#> 202  8.27     34.4 2.07 POINT (434890 5341870)

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: 431110 ymin: 5337730 xmax: 438550 ymax: 5343190
#> CRS:           +proj=utm +zone=17 +ellps=GRS80 +units=m +no_defs
#> First 10 features:
#>      zq90 pzabove2  zsd dist2access               geometry
#> 836  5.35     10.6 1.31   79.310924 POINT (434010 5340950)
#> 820 19.80     89.9 5.93  212.751165 POINT (437410 5341850)
#> 405  7.57     16.6 2.09    2.213413 POINT (438090 5340050)
#> 892 14.20     54.6 3.64  166.046692 POINT (434190 5342850)
#> 658 15.30     91.2 3.53  302.855301 POINT (432230 5340890)
#> 209 15.70     93.9 3.28  563.215819 POINT (433590 5338030)
#> 207 16.30     93.6 2.01  368.544895 POINT (433910 5342250)
#> 101 10.70     74.7 2.96  321.737976 POINT (437610 5338570)
#> 375 18.80     79.8 3.62  292.244242 POINT (432010 5340710)
#> 215  3.83      4.9 0.78   31.952217 POINT (437810 5342630)

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: 431190 ymin: 5337710 xmax: 438530 ymax: 5343230
#> CRS:           +proj=utm +zone=17 +ellps=GRS80 +units=m +no_defs
#> First 10 features:
#>      zq90 pzabove2  zsd dist2access               geometry
#> 450 22.70     87.0 5.19   118.90300 POINT (436830 5341430)
#> 242  8.17     15.4 2.65   196.19094 POINT (434950 5339150)
#> 180 14.00     96.3 2.36   143.62004 POINT (438370 5340730)
#> 459  9.70     41.7 2.64    99.58651 POINT (434630 5342290)
#> 434 14.10     78.6 2.90    61.83600 POINT (433550 5342130)
#> 190  9.71     26.0 2.72   130.68415 POINT (438230 5338090)
#> 117  3.93     18.8 0.96    77.90531 POINT (433270 5341070)
#> 220  6.48     81.5 1.36    82.85162 POINT (437130 5338030)
#> 350 17.50     94.1 4.62   133.22897 POINT (434890 5340550)
#> 439 17.00     86.2 4.40    75.81909 POINT (436190 5342230)

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.