Measures how well predictions match the frequency of presences, which is especially suited to presence-only data (Hirzel et al. 2006). The predicted/expected (P/E) ratio, the share of presences divided by the share of background points, is estimated along the range of predicted values; the index is the Spearman correlation between this ratio and the prediction. Values close to 1 mean presences become steadily more frequent as suitability increases, 0 means no better than random and negative values mean a wrong model.
Usage
boyce_index(
presence,
background,
n_windows = 100,
window_width = 0.1,
smooth = c("none", "spline", "gam", "loess"),
n_boot = 0,
conf = 0.95,
details = n_boot > 0,
n_points = 501,
span = 0.75,
seed = NULL
)Arguments
- presence
Predicted values at presence points.
- background
Predicted values at background (or absence) points, or at all cells of the study area.
- n_windows
Number of window positions (default 100), for
smooth = "none".- window_width
Window width as a proportion of the range of the background predictions (default 0.1), for
smooth = "none".- smooth
Estimator of the P/E curve:
"none"(moving window, the default),"spline","gam"or"loess"; see Details.- n_boot
Number of bootstrap resamples for a confidence interval (presences and background resampled separately). With
n_boot > 0the result hasdetails.- conf
Confidence level of the bootstrap interval.
- details
Return the P/E curve, the interval and diagnostics (a
boyce_indexobject) instead of a single number.- n_points
Number of equally spaced prediction values at which a smoothed curve is evaluated (501 as in Liu et al. 2024).
- span
Span of
smooth = "loess".- seed
Optional random seed for the bootstrap.
Value
A single number between -1 and 1, or NA when it cannot be
computed (e.g. too few distinct window ratios). With details = TRUE or
n_boot > 0, a list of class boyce_index with index, lower,
upper (bootstrap interval, NA without bootstrap), curve (the P/E
curve: prediction, pe and, with bootstrap, pe_lower, pe_upper),
boot (the bootstrap values), flat_p (smoothed curves: p-value of a
likelihood-ratio test against a flat P/E curve), n_presence,
n_background and smooth; it has a print method and
plot_boyce().
Details
Two estimators of the P/E curve.
smooth = "none"(default): a moving window slides along the range of predicted values and the ratio is computed in each window. This reproducesecospat::ecospat.boyce(), which biomod2 also uses. With few presences the ratios of neighbouring windows fluctuate, and every fluctuation lowers the correlation: in simulations the index was underestimated below about 50-200 presences (Liu et al. 2024).smooth = "spline","gam"or"loess": the probability that a point is a presence rather than a background point is modelled as a smooth function of the prediction, from all points at once (Liu et al. 2024). Its odds are proportional to the P/E ratio, so the index is the Spearman correlation between the fitted curve and the prediction atn_pointsequally spaced values over the range of the predictions."spline"is a penalised logistic regression spline (P-spline: cubic B-splines, 10 basis functions, second-order difference penalty chosen by UBRE, as mgcv does for binomial models), computed without extra packages;"gam"is the thin plate regression spline of Liu et al. (mgcv::gam(),k = 10; needs mgcv); both performed equally well in Liu et al. (2024)."loess"is a local regression of the 0/1 outcome (span), not evaluated by Liu et al.; it is less variable for flat curves but biased towards 0.
The smoothed index is much less variable with few presences and agrees
with the moving window for models whose P/E ratio rises steadily. Two
cautions, which is why the moving window stays the default: for a model
no better than random the fitted curve is almost a straight line, and the
Spearman correlation of any straight line is +1 or -1, so the smoothed
index of a random model swings across the whole range (in 200 simulated
random models with 50 presences it was 0.9 or more in a third, the
moving window never; check the bootstrap interval and the test of a flat
curve reported with details = TRUE); good models often score exactly 1
and tie, which makes it a weaker Pareto criterion; and for curves that rise and then fall the two
estimators can differ, so compare models with the same estimator.
Use background points that represent the whole study area (or all cells); absences sampled away from presences make the index unreliable.
References
Hirzel, A.H., Le Lay, G., Helfer, V., Randin, C., Guisan, A. (2006) Evaluating the ability of habitat suitability models to predict species presences. Ecological Modelling 199, 142-152.
Liu, C., Newell, G., White, M., Machunter, J. (2024) Improving the estimation of the Boyce index using statistical smoothing methods for evaluating species distribution models with presence-only data. Ecography 2025, e07218. doi:10.1111/ecog.07218
Eilers, P.H.C., Marx, B.D. (1996) Flexible smoothing with B-splines and penalties. Statistical Science 11, 89-121.
See also
plot_boyce(); the optional metric Boyce_smooth in
evaluate_models().
Examples
set.seed(1)
bg <- runif(1000)
pres <- rbeta(100, 4, 1) # presences mostly at high suitability
boyce_index(pres, bg)
#> [1] 0.9542812
boyce_index(pres, bg, smooth = "spline")
#> [1] 1
# few presences: P/E curve, bootstrap interval and diagnostics
b <- boyce_index(pres[1:20], bg, smooth = "spline", n_boot = 99, seed = 1)
b
#> Boyce index: 1.000 (95% bootstrap interval 0.814 to 1.000)
#> P/E curve: penalised regression spline; 20 presences, 1000 background points
#>
#> IN SHORT
#> - Presences become steadily more frequent as the predicted suitability
#> increases.
#>
#> The P/E ratio is the share of presences divided by the share of background
#> points at a predicted value; the index is its Spearman correlation with the
#> prediction (1 = P/E rises steadily, 0 = random). The wording "steadily"
#> (index >= 0.9), "with some reversals" (>= 0.5) and "weak" (below 0.5) is a
#> preENM default, not from the literature. Flat curve: likelihood-ratio test of
#> the smooth against a constant, p = 5.4e-05.
plot_boyce(b)
