Skip to contents

Given the coordinates, the species' name and the environmental variables, the function creates an SWD object (sample with data).

Usage

prepareSWD(
  species,
  env,
  p = NULL,
  a = NULL,
  categorical = NULL,
  verbose = TRUE
)

Arguments

species

character. The name of the species.

env

rast containing the environmental variables used to extract the values at coordinate locations.

p

data.frame. The coordinates of the presence locations.

a

data.frame. The coordinates of the absence/background locations.

categorical

vector indicating which of the environmental variable are categorical.

verbose

logical, if TRUE prints informative messages.

Value

An SWD object.

Details

The SWD object is created in a way that the presence locations are always before than the absence/background locations.

Author

Sergio Vignali

Examples

# Acquire environmental variables
files <- list.files(path = file.path(system.file(package = "dismo"), "ex"),
                    pattern = "grd",
                    full.names = TRUE)

predictors <- terra::rast(files)

# Prepare presence and background locations
p_coords <- virtualSp$presence
bg_coords <- virtualSp$background

# Create the SWD object
data <- prepareSWD(species = "Virtual species",
                   p = p_coords,
                   a = bg_coords,
                   env = predictors,
                   categorical = "biome")
#>  Extracting predictor information for presence locations
#>  Extracting predictor information for presence locations [20ms]
#> 
#>  Extracting predictor information for absence/background locations
#>  Extracting predictor information for absence/background locations [45ms]
#> 
data
#> 
#> ── Object of class: <SWD> ──
#> 
#> ── Info 
#>Species: Virtual species
#>Presence locations: 400
#>Absence locations: 5000
#> 
#> ── Variables 
#>Continuous: "bio1", "bio12", "bio16", "bio17", "bio5", "bio6", "bio7", and
#> "bio8"
#>Categorical: "biome"