get_env_bg: Extract background data for SDM fitting.

View source: R/get_env_bg.R

get_env_bgR Documentation

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
)

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

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).

Note

If supplying constraint_regions, any polygons in which the occurrences fall are considered fair game for background selection. This background selection is, however, still limited by the buffer as well.

Examples

{

# 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)


}

bmaitner/pbsdm documentation built on Feb. 8, 2025, 2:27 p.m.