Skip to contents

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.

Usage

varImp(model, permut = 10, progress = TRUE)

Arguments

model

SDMmodel or SDMmodelCV object.

permut

integer. Number of permutations.

progress

logical. If TRUE shows a progress bar.

Value

data.frame with the ordered permutation importance.

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.

Author

Sergio Vignali

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 [36ms]
#> 
#>  Extracting predictor information for absence/background locations
#>  Extracting predictor information for absence/background locations [62ms]
#> 

# 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     bio6                   54.2 0.008
#> 2     bio8                   27.4 0.005
#> 3    biome                   12.6 0.005
#> 4    bio12                    5.3 0.002
#> 5    bio16                    0.5 0.001
#> 6     bio5                    0.1 0.000
#> 7     bio1                    0.0 0.000
#> 8    bio17                    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  ■■■■■■■■■■■■                      36% | ETA:  2s - 00:00:01
#> Variable importance  ■■■■■■■■■■■■■■■■■■■■■■■           72% | ETA:  1s - 00:00:02
#> 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