Sampling.RmdLet’s start by attaching the necessary packages and setting the seed.
Next, we define the raster grid to sample points/locations from.
rast_grid = terra::rast(xmin = 0, xmax = 200, ymin = 0, ymax = 200,
ncols = 200, nrows = 200)Alternatively, we can read a raster from a file.
The simsam package supports several types of
sampling, including jittered, clustered, and random with the
sam_field() function. All these types of sampling require
the rast_grid object, the number of samples to create
(size), and a sampling method function created by
sample_*() functions.
The jittered sampling is a regular sample moved by an amount of
noise. The amount argument controls the amount of jitter.
Importantly, this sampling type ensures that all the samples fall within
the sampling window.
sample_j1 = sam_field(rast_grid, size = 100, method = sample_jittered(amount = 5))
plot(sample_j1)
sample_j2 = sam_field(rast_grid, size = 100, method = sample_jittered(amount = 20))
plot(sample_j2)
The clustered sampling creates samples forming groups of points with
similar locations. The outcome is controlled by the
nclusters and radius arguments, where the
former controls the number of clusters and the latter the radius of the
buffer around each cluster.
sample_c1 = sam_field(rast_grid, 100, method = sample_clustered(nclusters = 5, radius = 5))
plot(sample_c1)
sample_c2 = sam_field(rast_grid, 100, method = sample_clustered(nclusters = 5, radius = 10))
plot(sample_c2)
Random sampling creates samples with no spatial structure.
sample_r = sam_field(rast_grid, 100, method = sample_random())
plot(sample_r)