Chapter 4 Preparing design objects

4.1 Background

This document provides an example of generating the input objects for the optimal design function scrdesignGA() that is available in the spatial capture recapture R package oSCR. From the package help file (?scrdesignGA()):

scrdesignGA() implements a genetic algorithm to solve this k-of-n design problem. In the context of SCR, and for a given objective function and landscape, the function finds the best subset of sampling locations (k) from all possible sampling locations (n).

The functions requires the following input objects:

  • statespace: A discretized representation of the study area (state-space), defined as a convex hull around the trapping extent with an additional buffer of approximately 3*sigma to ensure the incorporation of the activity centers of all individuals that could be captured.

  • alltraps: A two-column dataframe, labelled X and Y accordingly, comprised of all possible trapping locations. These locations should be user-defined after accounting for logistic constraints, primarily accessibility. Design generation then relies on subsetting these locations.

The function also requires input values of beta0 and sigma which will come from literature, pilot studies, or best guesses, and the number of traps which will be defined by the user. We do not discuss these inputs any further except to say that in this example we use values of beta0 = 0.025, sigma =3.25, and ntraps = 50. Here the focus is on generating the statespace and alltraps objects.

Before getting started, a few packages should be loaded:

## Loading required package: viridisLite

4.2 Creating statespace from a polygon

Consider the motivating example in Dupont et al. (In review) where the interest is designing an SCR study in a areas defined by a watershed that can be represented as a polygon (pak_poly):

This polygon represents the general area within which traps (cameras) can be deployed. The help file suggests that the statespace should be “a convex hull around the trapping extent with an additional buffer of approximately \(3\times\sigma\)”. Creating the statespce object therefore requres first a buffering of the study area, then the creation of a regular grid of points withing that buffer.

4.2.1 Buffer the trappping area

The first step is to buffer pak_poly using a buffer width of \(3\times\sigma\). Sigma is 3.25, and three times that is 9.75. The projection of pak_poly is in UTM (i.e., meters), so we also need to make sure to convert sigma, which is in km, to m.

4.2.2 Generating a regular grid

The second step is to generate a regular grid of points within this area that represents the activity centers of all individuals that could be captured by any trap placed in pak_poly. This process is straightforward using the the spatial sampling function the the sf package (sf::st_sample()) and specifying type="regular". It does require that we approximate the number of points (the size argument), which requires that we also define the resolution (spacing) of this grid. We use a resolution of sigma, and therefore, the number of points is the area divided by the area of a pixel with sides equal to sigma:

4.2.3 Extracting the coordinates

The statespace object should be a 2-column matrix or dataframe countaining the X and Y coordinates. THese can be extrated directly from the spatial object ss_points using the coordinates() function. For convenience, here all coordinates are converted to the km scale (for UTM divide by 1000).

4.3 Creating alltraps from a polygon

4.3.1 Create all technically possible points

Using the same principles and functions as the previous section, the first step for creating the alltraps object is to generate a regular grid of points within this area that represents all possible trapping locations. We use \(0.5*\sigma\) here but as long as the spacing is not larger than sigma, the end result should not be effected\(^{\dagger}\). THis process is straightforward using the the spatial sampling function the the sf package (sf::st_sample()) and specifying type="regular".

\(^\dagger\) this has not been tested, but should be easy to test.

4.3.2 Create all practically possible points

Part of the motivation for developing this design selection framework was to accomodate sampling restrictions and logistical constraints in the design phase (as opposed to adjusting in situ). To demonstrate this in practice, sampling in these mountanous areas of the Pakistan snow leopard range has two obvious challenges:

  1. areas too steep cannot be sampled (we use a slope cut-off of 45°)
  2. areas to high (elevation) cannot be sampled (we use an elevation cut-off of 4500\(m\))

Elevation layers are availableso we use that (elev), and slope can be derived from that using the terrain() function from the raster package.

Using the extract() function from the raster package, we can extract the elevation and slope values for each potential trap location. Then, using the cut-off values, we can identify and select only those point that are ‘sampleable’. As with the statespce object, the alltraps object should be 2-column matrix or dataframe countaining the X and Y coordinates of the smple points.

The removal of points can also be done using a polygon that delineated unsampleable areas (e.g., cities or areas that are impossible to access). In the following example, we remove potential trapping points using a polygon called nogo_areas that represent inaccessible parts of the landscape.

Its much easier to use spatial objects to identify and remove overlapping regions:

4.4 Inspecting the objects

With both objects (statespace and alltraps) created, it is worth plotiing the objects to confirm they all line up in space.

Great! Both objects are created, are spatially aligned, and the units appear to be on the km scale. These are the landscape (statespace) and trap (alltraps) inputs for scrdesignGA().

If you have any issues or questions, we have a very responsive, and friendly user group.

Chris Sutherland