Skip to contents

Calibration asks whether predicted probabilities can be read as probabilities: among places predicted at 0.3, is the species found at about 30%? Discrimination (AUC, TSS, Boyce) cannot tell, because it only ranks the predictions; this is why MAE and balanced MAE are used next to AUC (Konowalik and Nosol 2021). The machine-learning literature has formalised the same idea into a standard toolkit (Silva Filho et al. 2023), which this function implements:

Usage

calibration_curve(
  obs,
  pred = NULL,
  bins = 10,
  binning = c("width", "count"),
  conf = 0.95,
  rescale = TRUE
)

Arguments

obs

Observations (1 = presence, 0 = absence/background), or a table from extract_predictions() (a data.frame with obs and one column per model): then pred is not needed and every model gets its curve.

pred

Predicted probabilities (between 0 and 1).

bins

Number of bins.

binning

"width" (equal-width bins over the range of the predictions) or "count" (equal numbers of points).

conf

Confidence level of the intervals.

rescale

For a table of several models: bring each to the 0-1 scale (models on 0-100 or 0-1000 are divided by 100 or 1000, with a message); see extract_predictions().

Value

A list of class calibration_curve with bins (one row per model and bin: n, mean_pred, observed, lower, upper) and summary (one row per model: n, slope, slope_lo, slope_hi, intercept, intercept_lo, intercept_hi, brier, and the Brier decomposition of brier_decompose()).

Details

  • Reliability diagram. The predictions are cut into bins, of equal width over their range or with equal numbers of points (binning = "count"). For each bin, the observed frequency of presences is plotted against the mean prediction of the bin (not the bin centre, which can make a well calibrated model look miscalibrated by up to half a bin), with a binomial (Clopper-Pearson) confidence interval. Points on the 1:1 line mean good calibration.

  • Calibration slope: the slope of a logistic regression of the observations on the logit of the predictions. 1 = calibrated; below 1 the predictions are too extreme (over-confident: high ones too high, low ones too low); above 1 too moderate (under-confident).

  • Calibration intercept (calibration-in-the-large): the intercept of the same regression with the slope fixed at 1. 0 = calibrated; above 0 the predictions are too low on average, below 0 too high.

Presence-background data. With background points instead of true absences, the "observed frequency" is the share of presences among the presences and background points of a bin. It depends on how many background points there are and on how well they represent the environment of the study area (the environmental representativeness effect; Jimenez-Valverde 2025, 2026). Then these quantities compare models evaluated on the same presences and background; they do not measure calibration in absolute terms. Predictions that are not probabilities (e.g. raw Maxent output) cannot be calibrated.

References

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

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

Jimenez-Valverde, A. (2025) Refining uniform discrimination metrics: towards a case-by-case weighting evaluation in species distribution models with presence-absence data. Ecology and Evolution 15, e72573. doi:10.1002/ece3.72573

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

set.seed(1)
p <- runif(2000)
y <- rbinom(2000, 1, p)                  # calibrated
calibration_curve(y, p)
#> Calibration of the predictions (10 bins of equal width)
#> 
#>     n slope slope_lo slope_hi intercept brier reliability resolution
#>  2000 1.008    0.914    1.103    -0.009 0.164           0      0.087
#> 
#> IN SHORT
#> - Consistent with calibration: the spread of the predictions fits the
#>   observations and on average they fit. Slope 1.01 (95% interval 0.91 to
#>   1.10), intercept -0.01 (95% interval -0.12 to 0.10).
#> 
#> With background points instead of absences, compare only models evaluated on
#> the same presences and background: the values depend on the number and
#> environmental representativeness of the background points (Jimenez-Valverde
#> 2025, 2026).
#> 
#> Definitions: the calibration slope is the slope of a logistic regression of
#> the observations on the logit of the predictions (1 = calibrated, below 1
#> over-confident, above 1 under-confident); the intercept is that of the same
#> regression with the slope fixed at 1 (0 = calibrated, above 0 predictions too
#> low on average). "Slightly" marks slopes between 0.8 and 1.25, a preENM
#> default, not from the literature. Brier = reliability - resolution +
#> uncertainty (+ two small within-bin terms, see brier_decompose()).
# over-confident: the same ranking, more extreme probabilities
p_over <- plogis(2 * qlogis(p))
cc <- calibration_curve(y, p_over)
cc
#> Calibration of the predictions (10 bins of equal width)
#> 
#>     n slope slope_lo slope_hi intercept brier reliability resolution
#>  2000 0.504    0.457    0.551     0.016 0.174        0.01      0.085
#> 
#> IN SHORT
#> - Over-confident: the predictions are too extreme, high ones too high and
#>   low ones too low; on average they fit. Slope 0.50 (95% interval 0.46 to
#>   0.55), intercept 0.02 (95% interval -0.12 to 0.15).
#> 
#> With background points instead of absences, compare only models evaluated on
#> the same presences and background: the values depend on the number and
#> environmental representativeness of the background points (Jimenez-Valverde
#> 2025, 2026).
#> 
#> Definitions: the calibration slope is the slope of a logistic regression of
#> the observations on the logit of the predictions (1 = calibrated, below 1
#> over-confident, above 1 under-confident); the intercept is that of the same
#> regression with the slope fixed at 1 (0 = calibrated, above 0 predictions too
#> low on average). "Slightly" marks slopes between 0.8 and 1.25, a preENM
#> default, not from the literature. Brier = reliability - resolution +
#> uncertainty (+ two small within-bin terms, see brier_decompose()).
plot_calibration(cc)