
Evaluate one or many models and rank them by Pareto optimality
Source:R/evaluate.R
evaluate_models.RdThe main entry point of the package. Extracts predictions at presence and
absence/background points, computes AUC, MAE, bias, TSS and the Boyce
index (plus any metrics you add), and ranks models by Pareto optimality on
the chosen criteria. The default, AUC (maximised) and MAE (minimised), is
the combination recommended by Konowalik & Nosol (2021).
Usage
evaluate_models(
models = NULL,
presence = NULL,
absence = NULL,
criteria = c(AUC = "max", MAE = "min"),
metrics = NULL,
n_boot = 0,
conf = 0.95,
weights = NULL,
tol = 0,
coords = NULL,
points_crs = "EPSG:4326",
na_action = c("common", "per_model"),
boot_metrics = c("criteria", "all"),
seed = NULL,
data = NULL,
rescale = TRUE,
data_type = c("background", "absence", "pseudo_absence"),
boot_blocks = NULL,
rank_by = c("compromise", "front"),
crs = NULL
)Arguments
- models
Model predictions: a terra::SpatRaster (one layer per model), file path(s) to rasters, or a named list of these.
- presence
Presence points (data.frame, CSV path,
sforSpatVector).- absence
Absence points or, for presence-only data, background / pseudo-absence points (same formats as
presence).- criteria
Named vector of the metrics to compare and their direction (
"max","min","zero"or"one"); see Details. Defaultc(AUC = "max", MAE = "min").- metrics
Optional extra metrics: a named list of functions
function(obs, pred)returning a single number (obsis 0/1,predthe predicted suitability), and/or names of optional metrics ("calibration_slope","calibration_intercept","brier","Boyce_smooth"), e.g.metrics = "brier"to add the Brier score to the table.- n_boot
Number of bootstrap resamples (0 = no bootstrap). 500 to 1000 is a good choice for final results.
- conf
Confidence level for bootstrap intervals (default 0.95).
- weights
Optional named vector of the relative importance of the criteria in the compromise score (default: equal); see
pareto_rank().- tol
Tolerance for Pareto ties; see
pareto_rank().- coords
Optional names of the x/longitude and y/latitude columns when points are tabular. Detected automatically if
NULL.- points_crs
CRS of tabular coordinates (default WGS84,
"EPSG:4326").- na_action
How to handle points that fall on
NAcells."common"(default) drops a point for all models if it isNAin any model, so every model is evaluated on exactly the same points (a fair comparison)."per_model"keeps points independently for each model (this reproduces the original 2021 script).- boot_metrics
Metrics that get bootstrap intervals:
"criteria"(default) or"all"metrics (slower, mainly because of the Boyce index).- seed
Optional random seed for reproducible bootstraps.
- data
Optionally, a table returned by
extract_predictions(). When supplied,models,presenceandabsenceare ignored. This is also useful when predictions were extracted with other software: supply a data.frame with a 0/1 columnobsand one numeric column per model. Missing predictions (NA) are allowed: each model is then evaluated on the points it has (also in the bootstrap), so do not drop rows with anNAin one model, which would remove those points for all models. With out-of-fold predictions from cross-validation (each point predicted by the model that did not see it), this bootstraps the pooled hold-out predictions.- rescale
Bring the predictions of every model to the 0-1 scale (models on 0-100 or 0-1000 are divided by 100 or 1000, with a message); see
extract_predictions(). Algorithms differ in their output scale, and MAE, bias, calibration and ensembles are only comparable on one scale.- data_type
What the zeros are:
"background"(default; background points),"absence"(recorded absences) or"pseudo_absence". It does not change the numbers; the printout says what the metrics mean for this kind of data, which matters most for MAE, bias and calibration.- boot_blocks
Block bootstrap for spatially clustered points: a block size in km (square blocks in an equal-area projection; needs
models,presenceandabsence), or one block id per evaluation point, e.g.attr(spatial_folds(...), "block"). Whole blocks are resampled, so nearby points, which are not independent, move together and the intervals are wider and more honest.NULL(default) resamples single points.- rank_by
"compromise"(default): Pareto front, then bootstrap robustness, then the compromise distance to the ideal point."front": Pareto front (and bootstrap robustness) only; models of one front share a rank, anddistanceis reported but not used.- crs
Deprecated: the former name of
points_crs, still accepted with a warning.
Value
An object of class enm_evaluation (a data.frame) with one row per
model and columns model, AUC, MAE, bias, TSS, Boyce, any
extra metrics, n_presence, n_absence, pareto_front (1 =
non-dominated on the criteria), distance (normalised distance to the
ideal point, lower is better) and rank. With bootstrapping there are
also <criterion>_lower, <criterion>_upper and <criterion>_sd for
each criterion, and p_pareto. The bootstrap replicates are stored in
attr(x, "bootstrap") and the criteria in attr(x, "criteria").
Details
Choosing the metrics to compare. criteria can be any of the computed
metrics, each with a direction: "max" (higher is better), "min"
(lower is better), "zero" (closer to 0 is better) or "one" (closer
to 1 is better). For example
c(AUC = "max", TSS = "max"), c(Boyce = "max", MAE = "min") or three
criteria c(AUC = "max", MAE = "min", bias = "zero").
Calibration as a criterion. Three optional metrics are computed when
they are named in criteria or in metrics: calibration_slope
(closer to 1 is better), calibration_intercept (closer to 0 is better)
and brier (the Brier score, lower is better); see
calibration_curve() and brier_score(). Together with AUC and MAE they
give the three sides of an evaluation: discrimination, calibration and
ranking, e.g. criteria = c(AUC = "max", calibration_slope = "one").
With background points instead of absences they compare models evaluated
on the same background only, not absolute calibration
(Jimenez-Valverde 2025, 2026; see calibration_curve()). They need
predictions on the 0-1 scale (otherwise NA).
Smoothed Boyce index. The optional metric Boyce_smooth is the Boyce
index from a smoothed P/E curve (boyce_index(smooth = "spline"); Liu et
al. 2024), steadier than Boyce with few presences; see
boyce_index() for its caveats.
Your own metrics are
added with metrics, e.g.
metrics = list(Brier = function(obs, pred) mean((obs - pred)^2)), and can
then be used in criteria (c(AUC = "max", Brier = "min")).
When n_boot > 0, evaluation points are resampled with replacement
(separately for presences and absences, so their numbers stay fixed) and all
models are re-evaluated on each resample. This gives:
percentile confidence intervals for every criterion, and
p_pareto: the proportion of resamples in which the model lies on the Pareto front. It shows how robust the selection is: a model withp_pareto = 0.95is almost always among the best trade-offs, while0.20means it reached the front partly by chance.
Single points are resampled independently by default. Records are
usually clustered, and nearby points are not independent, so this
understates the uncertainty; boot_blocks resamples whole spatial
blocks instead (a cluster bootstrap), which keeps the clustering in each
resample.
Assumptions and limits. The default pair, AUC and MAE, agreed best
with verification against independent distribution data in Konowalik &
Nosol (2021); it is a default, not the best pair for every study, and any
computed metrics can be used instead. With background points instead of
absences, AUC measures discrimination of presences from the background,
and MAE, bias and the calibration metrics do not measure the error of
occurrence probabilities; data_type puts this in the printout. Without
boot_blocks the bootstrap resamples points independently, which
understates the uncertainty when records are spatially clustered.
References
Konowalik, K., Nosol, A. (2021) Evaluation metrics and validation of presence-only species distribution models based on distributional maps with varying coverage. Scientific Reports 11, 1482. doi:10.1038/s41598-020-80062-1
Silva Filho, T., Song, H., Perello-Nieto, M., Santos-Rodriguez, R., Kull, M., Flach, P. (2023) Classifier calibration: a survey on how to assess and improve predicted class probabilities. Machine Learning 112, 3211-3260. doi:10.1007/s10994-023-06336-7
Jimenez-Valverde, A. (2026) The environmental representativeness effect in species distribution model evaluation without absence data. Biodiversity Informatics 20, 74-80. doi:10.17161/bi.v20i1.24860
Examples
sim <- simulate_enm_data(seed = 1)
res <- evaluate_models(sim$models, sim$presence, sim$absence,
n_boot = 100, seed = 1)
res
#> ENM evaluation: 7 model(s), 100 presence and 300 absence/background points
#> Data: presences against background points. AUC measures how well the models
#> separate presences from the background; MAE, bias, the specificity in TSS
#> and the calibration metrics treat background points as absences, so they
#> compare models evaluated on the same background, not absolute errors of
#> occurrence probability.
#> Bootstrap: 100 resamples of single points, 95% percentile intervals
#> (points resampled independently; with spatially clustered records use boot_blocks)
#> Criteria: AUC (higher is better), MAE (lower is better)
#> Pareto front (best trade-offs): Maxent_LQ, GLM, Maxent_H_rm4
#>
#> rank model AUC AUC_lower AUC_upper MAE MAE_lower MAE_upper MAEbal
#> 1 Maxent_LQ 0.980 0.966 0.990 0.164 0.144 0.181 0.146
#> 2 GLM 0.981 0.969 0.992 0.316 0.294 0.337 0.228
#> 3 Maxent_H_rm4 0.980 0.969 0.989 0.247 0.232 0.268 0.232
#> 4 RandomForest 0.978 0.963 0.990 0.204 0.194 0.217 0.289
#> 5 GBM 0.968 0.949 0.982 0.239 0.218 0.260 0.210
#> 6 BIOCLIM 0.821 0.774 0.864 0.623 0.612 0.635 0.428
#> 7 Random 0.457 0.401 0.525 0.522 0.492 0.548 0.521
#> bias TSS Boyce pareto_front p_pareto distance
#> -0.109 0.850 0.908 1 1.00 0.001
#> -0.290 0.883 0.911 1 0.44 0.234
#> -0.146 0.857 0.961 1 0.37 0.128
#> 0.027 0.877 0.941 2 0.34 0.062
#> -0.162 0.820 0.978 3 0.05 0.116
#> -0.604 0.587 0.830 4 0.00 0.739
#> -0.261 0.033 -0.263 4 0.00 0.896
#>
#> A preENM sensitivity analysis: how much the result depends on the
#> evaluation points behind the ranking of models. The others are listed in
#> ?sensitivity_analyses.
plot_pareto(res)
# compare other metrics, e.g. TSS and the Boyce index
res2 <- evaluate_models(sim$models, sim$presence, sim$absence,
criteria = c(TSS = "max", Boyce = "max"))
plot_pareto(res2)
# add your own metric and use it as a criterion
brier <- function(obs, pred) mean((obs - pred)^2)
res3 <- evaluate_models(sim$models, sim$presence, sim$absence,
metrics = list(Brier = brier),
criteria = c(AUC = "max", Brier = "min"))