This function calculates the uncertainty of a species distribution model by performing a bootstrap procedure. It refits the model multiple times on resampled data and then calculates the standard deviation of the predictions across all iterations.
Usage
sdm_uncertainty(
models,
training_data,
background = NULL,
response,
projection_data,
iteration = 50,
n_cores = 5,
clamp = TRUE,
pred_type = "cloglog"
)
Arguments
- models
A flexsdm model object from `fit_*` and `tune_*` functions.
- training_data
A data.frame or tibble with presence-absence/background data and predictors.
- background
A data.frame or tibble with background data, used for Maxent and Gausian Process models. Default NULL.
- response
character. Column name of the response variable.
- projection_data
A SpatRaster object with the environmental layers for projection.
- iteration
numeric. The number of bootstrap iterations. A large number of iterations will increase computation time, especially for large areas or high-resolution data. Default 50.
- n_cores
numeric. The number of cores to use for parallel processing. Default 5.
- clamp
logical. If TRUE, predictors and features are restricted to the range seen during model training. Only for Maxent models. Default TRUE.
- pred_type
character. The type of response required. Available options are: "link", "exponential", "cloglog", and "logistic". Only for Maxent models. Default "cloglog".
Value
A SpatRaster object with a single layer representing the model uncertainty, calculated as the standard deviation of the bootstrap predictions.
Examples
if (FALSE) { # \dontrun{
require(terra)
require(dplyr)
data(spp)
somevar <- system.file("external/somevar.tif", package = "flexsdm")
somevar <- terra::rast(somevar)
sp_data <- spp %>% filter(species == "sp3")
sp_data <- part_random(
data = sp_data,
pr_ab = "pr_ab",
method = c(method = "kfold", folds = 3)
)
sp_data <- sdm_extract(
data = sp_data,
x = "x",
y = "y",
env_layer = somevar
)
m <- fit_svm(
data = sp_data,
response = "pr_ab",
predictors = c("CFP_1", "CFP_2", "CFP_3", "CFP_4"),
partition = ".part"
)
unc <- sdm_uncertainty(
models = m,
training_data = sp_data,
response = "pr_ab",
projection_data = somevar,
iteration = 10,
n_cores = 2
)
plot(unc)
} # }