Learn R Programming

S4DM (version 0.0.1)

get_env_bg: Extract background data for SDM fitting.

Description

This function extracts background data around known presence records.

Usage

get_env_bg(
  coords,
  env,
  method = "buffer",
  width = NULL,
  constraint_regions = NULL,
  standardize = TRUE
)

Value

A list containing 1) the background data (env), 2) the cell indices for which the background was taken (buffer_cells), 3) the environmental means (env_mean; NA if standardization not done), and 4) the environmental standard deviations (env_sds; NA if standardization not done).

Arguments

coords

Coordinates (long,lat) to extract values for

env

Environmental SpatRaster(s) in any projection

method

Methods for getting bg points. Current option is buffer

width

Numeric or NULL. Width (meters or map units) of buffer. If NULL, uses max dist between nearest occurrences.

constraint_regions

An optional spatialpolygons* object that can be used to limit the selection of background points.

standardize

Logical. If TRUE, the variables will be scaled and centered

Examples

Run this code
{

# load in sample data

 library(S4DM)
 library(terra)

 # occurrence points
   data("sample_points")
   occurrences <- sample_points

 # environmental data
   env <- rast(system.file('ex/sample_env.tif', package="S4DM"))

 # rescale the environmental data

   env <- scale(env)

bg_data <- get_env_bg(coords = occurrences,
                      env = env,
                      method = "buffer",
                      width = 100000)


}

Run the code above in your browser using DataLab