Skip to contents

Summarises variable importance from models fitted with the real predictors together with random ones (see random_variables()), in any software and for any number of algorithms and runs. In each run, a real predictor beats random when its importance is above that of the random variables. A predictor is kept unless it fails to beat random in most runs of most algorithms, the consensus rule of Konowalik (2022): algorithms measure importance differently, and a predictor that only one of them finds useless may still matter.

Usage

compare_to_random(
  importance,
  variable = "variable",
  value = "importance",
  algorithm = NULL,
  run = NULL,
  random = "^random",
  threshold = "max",
  min_runs = 0.5,
  coordinates = NULL
)

Arguments

importance

A data.frame in long format: one row per variable, algorithm and run.

variable, value

Columns with the variable name and its importance (any measure where larger means more important: contribution, permutation importance, gain, ...).

algorithm, run

Optional columns with the algorithm and the run (replicate, fold or background set). Without them all rows are one run of one algorithm.

random

Regular expression that recognises the random variables by name.

threshold

What a predictor must exceed in a run: "max", the most important random variable (strict; the more random variables, the stricter), or a number between 0 and 1, that quantile of the random variables (e.g. 0.5 for their median).

min_runs

Share of the runs of an algorithm in which a predictor must beat random to count as supported by that algorithm.

coordinates

Optional regular expression naming coordinate layers fitted together with the predictors (e.g. from coordinate_layers()). They are left out of the predictors, and each predictor is also compared with them: one that does not beat the most important coordinate layer in most runs may stand in for geography rather than for the environment.

Value

A data.frame with one row per real predictor: the share of runs in which it beats random, one column per algorithm; algorithms (how many support it); mean_importance; and keep (FALSE when most algorithms do not support it), ordered from the best supported. With coordinates: beats_coordinates (share of runs, averaged over algorithms, in which it beats the coordinate layers) and geography_like (TRUE below min_runs). attr(, "random") holds the threshold of every run.

Details

After removing the predictors that are not kept, fit the models again (with new random variables) and repeat until all remaining predictors are kept: importance is shared among predictors, so it changes when one is removed.

Assumptions and limits. Importance is measured differently by each algorithm and shared among correlated predictors, so a predictor can fail to beat random because a correlated one took its importance. With one random variable or few runs the comparison is noisy. What to vary. The number of random variables and runs, and the type of random layer in random_variables(): spatially structured ("field") layers are the stricter test. With coordinates, a third reference: models that can use longitude and latitude directly show which predictors carry more than geographic position.

References

Konowalik, K. (2022) Phylogeography and colonization pattern of subendemic round-leaved oxeye daisy from the Dinarides to the Carpathians. Scientific Reports 12, 16443. doi:10.1038/s41598-022-19619-1

Examples

imp <- data.frame(
  algorithm = rep(c("maxent", "rf", "gbm"), each = 5),
  variable = rep(c("bio1", "bio12", "wind", "random_1", "random_2"), 3),
  importance = c(52, 30, 4, 8, 6,   40, 35, 12, 9, 4,   61, 25, 2, 7, 5))
compare_to_random(imp)
#>   variable maxent rf gbm algorithms mean_importance  keep
#> 1     bio1      1  1   1          3              51  TRUE
#> 2    bio12      1  1   1          3              30  TRUE
#> 3     wind      0  1   0          1               6 FALSE