# NOT RUN {
# Acquire environmental variables
files <- list.files(path = file.path(system.file(package = "dismo"), "ex"),
pattern = "grd", full.names = TRUE)
predictors <- raster::stack(files)
# Prepare presence locations
p_coords <- condor[, 1:2]
# Prepare background locations
bg_coords <- dismo::randomPoints(predictors, 10000)
# Create SWD object
presence <- prepareSWD(species = "Vultur gryphus", coords = p_coords,
env = predictors, categorical = "biome")
bg <- prepareSWD(species = "Vultur gryphus", coords = bg_coords,
env = predictors, categorical = "biome")
# Get subsample of background to train the model, we will use the full
# dataset to compute the correlation among the environmental variables
bg_model <- getSubsample(bg, 5000, seed = 25)
# Split presence locations in training (80%) and testing (20%) datasets
datasets <- trainValTest(presence, test = 0.2)
train <- datasets[[1]]
test <- datasets[[2]]
# Train a Maxent model
model <- train(method = "Maxent", p = train, a = bg_model, fc = "l")
# Remove variables with correlation higher than 0.7 accounting for the AUC,
# in the following example the variable importance is computed as permutation
# importance
vs <- varSel(model, metric = "auc", bg4cor = bg, test = test, cor_th = 0.7,
permut = 1)
vs
# Remove variables with correlation higher than 0.7 accounting for the TSS,
# in the following example the variable importance is the MaxEnt percent
# contribution
vs <- varSel(model, metric = "tss", bg4cor = bg, test = test, cor_th = 0.7,
use_pc = TRUE)
vs
# Remove variables with correlation higher than 0.7 accounting for the aicc,
# in the following example the variable importance is the MaxEnt percent
# contribution
vs <- varSel(model, metric = "aicc", bg4cor = bg, cor_th = 0.7,
use_pc = TRUE, env = predictors)
vs
# }
Run the code above in your browser using DataLab