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_sdmorinput_sdmobject.- pred
A
sdm_areaobject. IfNULLandoccis ainput_sdm,predwill be retrieved fromocc.- 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. IfNULLthen 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 inn_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, thennis set to 500. Standard is NULL. This argument overwritesn.- i
A
input_sdmobject.
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.
See also
link{input_sdm} pseudoabsences occurrences_sdm
get_occurrences get_predictors
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.
