The function randomly permutes one variable at time (using training and absence/background datasets) and computes the decrease in training AUC. The result is normalized to percentages. Same implementation of MaxEnt java software but with the additional possibility of running several permutations to obtain a better estimate of the permutation importance. In case of more than one permutation (default is 10) the average of the decrease in training AUC is computed.
Arguments
- model
SDMmodel or SDMmodelCV object.
- permut
integer. Number of permutations.
- progress
logical. If
TRUE
shows a progress bar.
Details
Note that it could return values slightly different from MaxEnt Java software due to a different random permutation.
For SDMmodelCV objects the function returns the average and the standard deviation of the permutation importances of the single models.
Examples
# Acquire environmental variables
files <- list.files(path = file.path(system.file(package = "dismo"), "ex"),
pattern = "grd",
full.names = TRUE)
predictors <- terra::rast(files)
# Prepare presence and background locations
p_coords <- virtualSp$presence
bg_coords <- virtualSp$background
# Create SWD object
data <- prepareSWD(species = "Virtual species",
p = p_coords,
a = bg_coords,
env = predictors,
categorical = "biome")
#> ℹ Extracting predictor information for presence locations
#> ✔ Extracting predictor information for presence locations [20ms]
#>
#> ℹ Extracting predictor information for absence/background locations
#> ✔ Extracting predictor information for absence/background locations [45ms]
#>
# Split presence locations in training (80%) and testing (20%) datasets
datasets <- trainValTest(data,
test = 0.2,
only_presence = TRUE)
train <- datasets[[1]]
test <- datasets[[2]]
# Train a model
model <- train(method = "Maxnet",
data = train,
fc = "l")
# Compute variable importance
vi <- varImp(model,
permut = 5)
vi
#> Variable Permutation_importance sd
#> 1 bio8 41.6 0.006
#> 2 bio6 31.6 0.010
#> 3 biome 20.0 0.003
#> 4 bio12 5.8 0.002
#> 5 bio17 0.8 0.001
#> 6 bio5 0.3 0.000
#> 7 bio1 0.0 0.000
#> 8 bio16 0.0 0.000
#> 9 bio7 0.0 0.000
# Same example but using cross validation instead of training and testing
# datasets
# Create 4 random folds splitting only the presence locations
folds = randomFolds(data,
k = 4,
only_presence = TRUE)
model <- train(method = "Maxnet",
data = data,
fc = "l",
folds = folds)
# Compute variable importance
vi <- varImp(model,
permut = 5)
#> Variable importance ■■■■■■■■■■■■■ 39% | ETA: 2s - 00:00:01
#> Variable importance ■■■■■■■■■■■■■■■■■■■■■■ 69% | ETA: 1s - 00:00:2…
#> Variable importance ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 100% | ETA: 0s - 00:00:2…
#>
vi
#> Variable Permutation_importance sd
#> 1 bio6 60.575 12.898
#> 2 bio8 19.900 10.478
#> 3 biome 10.900 6.154
#> 4 bio12 6.825 2.350
#> 5 bio5 1.700 1.990
#> 6 bio17 0.175 0.287
#> 7 bio1 0.000 0.000
#> 8 bio16 0.000 0.000
#> 9 bio7 0.000 0.000