Skip to contents

This function obtains background data given a set of predictors.

Usage

background(occ,
           pred = NULL,
           method = "random",
           n_set = 1,
           n_bg = 10000,
           proportion = NULL)

n_background(i)

background_method(i)

background_data(i)

Arguments

occ

A occurrences_sdm or input_sdm object.

pred

A sdm_area object. If NULL and occ is a input_sdm, pred will be retrieved from occ.

method

Method to obtain the background data. One of: "random" or a custom function (see details).

n_set

numeric. Number of datasets of background data to create.

n_bg

numeric. Number of background records to be generated in each dataset created. If NULL then the function prevents imbalance by using the same number of presence records (n_records(occ)). If you want to address different sizes to each species, you must provide a named vector (as in n_records(occ)).

proportion

numeric. A number between 0 and 1 representing a proportion of the area to be mapped as background. E.g.: if the whole area has 5,000 cells and proportion is 0.1, then n is set to 500. Standard is NULL. This argument overwrites n.

i

A input_sdm object.

Value

A occurrences_sdm or input_sdm object with background data.

Details

background is used in the SDM workflow to obtain background data, a step necessary for MaxEnt algorithm to run. This function helps avoid the use of pseudoabsence data in background algorithms and the use of background data in pseudoabsence algorithms, a very common mistake. If user provides a custom function, it must have the arguments env_sf and occ_sf, which will consist of two "sf"s. The first has the predictor values for the whole study area, while the second has the presence records for the species. The function must return a vector with cell_ids of the pseudoabsences.

n_background returns the number of background records obtained per species.

background_data returns a list of species names. Each species name will have a lists with background data from class sf.

Author

Luíz Fernando Esser (luizesser@gmail.com) https://luizfesser.wordpress.com

Examples

# Create sdm_area object:
sa <- sdm_area(parana, cell_size = 25000, crs = 6933)
#> ! Making grid over study area is an expensive task. Please, be patient!
#>  Using GDAL to make the grid and resample the variables.

# Include predictors:
sa <- add_predictors(sa, bioc) |> select_predictors(c("bio1", "bio4", "bio12"))
#> ! Making grid over the study area is an expensive task. Please, be patient!
#>  Using GDAL to make the grid and resample the variables.

# Include scenarios:
sa <- add_scenarios(sa)

# Create occurrences:
oc <- occurrences_sdm(occ, crs = 6933)

# Create input_sdm:
i <- input_sdm(oc, sa)
#> Warning: Some records from `occ` do not fall in `pred`.
#>  2 elements from `occ` were excluded.
#>  If this seems too much, check how `occ` and `pred` intersect.

# Background generation:
i <- background(i, proportion = 1) # All available data is obtained as background data.
#> → Proportion is 1 Setting all species to have 373 background records.
#> → Background number is higher than the total data available.
#> Setting the number of background data to be 373.