Sampling.Rmd
Let’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 the type of sampling (type
).
The jittered sampling is a regular sample moved by an amount of
noise. The value
parameter controls the amount of jitter.
Importantly, this sampling type ensures that all the samples fall within
the sampling window.
The clustered sampling creates samples forming groups of points with
similar locations. The outcome is controlled by the
nclusters
and value
parameters, where the
former controls the number of clusters and the latter the amount of
noise (location variance) within each cluster.
Random sampling creates samples with no spatial structure.
Moreover, the sam_field()
function can be used with
additional arguments passed to the terra::spatSample()
function, when the type
is not specified. In such cases,
the method
argument can be used to control the sampling
method, e.g., method = "regular"
or
method = "random"
and the exhaustive
argument
to sample only from not NA areas in the input raster.