prepareTrainingData: Prepares training data for SDMs

Description Usage Arguments Value Author(s) References Examples

View source: R/prepareTrainingData.R

Description

Produces "presence-only", "background" and "restricted background" data to fit species distribution models. The background is selected at random within the provided raster brick or stack, while the restricted background is selected within a buffer (usually based on the maximum dispersal distance of the target species) around the presence records. The selection of background points is made by the function randomPoints, from the dismo package (Hijmans et al. 2017). The function can also apply thinning to the presence coordinates to reduce spatial autocorrelation through the function reduceSpatialCorrelation. To produce pseudo-absences instead of background data, just reduce the argument n to a number between the number and presences and twice the number of presences.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
prepareTrainingData(
  xy,
  variables,
  n = 10000,
  presence.only = FALSE,
  background = TRUE,
  restricted.background = FALSE,
  restricted.background.buffer = 200,
  plot = TRUE,
  thinning = FALSE,
  minimum.distance = raster::xres(variables)
  )

Arguments

xy

A data frame with two columns with coordinates x and y representing presence records. Column names are irrelevant as long as the first column represents the x coordinate, and the second column represents the y coordinate.

variables

A raster brick or stack with environmental variables. Must be in the same reference system of xy.

n

Integer, number of background points to generate. To generate pseudo-absences just define a low n (i.e. twice the number of presences). If n is larger than the number of valid cells in variables, then all cells are selected as background.

presence.only

Boolean. If TRUE, all other options are set to FALSE, and the function returns presence-only data.

background

Boolean. If TRUE, all other options are set to FALSE, and the function returns background data generated to the extension of variables.

restricted.background

Boolean. If TRUE, all other options are set to FALSE, and the function returns restricted background data generated within a buffer of width equeal to restricted.background.buffer around the presence records xy.

restricted.background.buffer

Integer, buffer in kilometres around xy over which to define the buffer delimiting the restricted background.

plot

Boolean. If TRUE, the output data is plotted.

thinning

Boolean. If TRUE, the function reduceSpatialCorrelation is applied to xy to reduce the spatial aggregation of the data.

minimum.distance

Numeric, minimum distance between consecutive points in the output dataset. Defaults to the resolution of variables. The minimum distance can be extracted from the resolution of variables, as in minimum.distance <- xres(variables).

Value

A data frame ready to fit an species distribution model.

Author(s)

Blas Benito <blasbenito@gmail.com>. The function randomPoints is authored by Robert J. Hijmans.

References

Robert J. Hijmans, Steven Phillips, John Leathwick and Jane Elith (2017). dismo: Species Distribution Modeling. R package version 1.1-4. https://CRAN.R-project.org/package=dismo

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
## Not run: 
data(virtualSpecies)
data(europe2000)

#presence-only data
presence.only <- prepareTrainingData(
  xy = virtualSpecies$observed.presence,
  variables = europe2000,
  n,
  presence.only = TRUE,
  plot = TRUE
)

#background
background <- prepareTrainingData(
  xy = virtualSpecies$observed.presence,
  variables = europe2000,
  n,
  background = TRUE,
  plot = TRUE
)

#restricted background
restricted.background <- prepareTrainingData(
  xy = virtualSpecies$observed.presence,
  variables = europe2000,
  n,
  restricted.background = TRUE,
  restricted.background.buffer = 100,
  plot = TRUE
)

#applying thinning
restricted.background <- prepareTrainingData(
  xy = virtualSpecies$observed.presence,
  variables = europe2000,
  n = 1000,
  restricted.background = TRUE,
  restricted.background.buffer = 100,
  plot = TRUE,
  thinning = TRUE,
  minimum.distance = raster::xres(europe2000)
)

## End(Not run)

BlasBenito/SDMworkshop documentation built on March 4, 2020, 4:16 a.m.