# Acquire environmental variables
files <- list.files(path = file.path(system.file(package = "dismo"), "ex"),
pattern = "grd",
full.names = TRUE)
predictors <- terra::rast(files)
# Prepare background locations
bg_coords <- terra::spatSample(predictors,
size = 10000,
method = "random",
na.rm = TRUE,
xy = TRUE,
values = FALSE)
# Create SWD object
bg <- prepareSWD(species = "Virtual species",
a = bg_coords,
env = predictors,
categorical = "biome")
# Get the correlation among all the environmental variables
corVar(bg,
method = "spearman")
# Get the environmental variables that have a correlation greater or equal to
# the given threshold
corVar(bg,
method = "pearson",
cor_th = 0.8)
Run the code above in your browser using DataLab