
Are the models better than expected from where records are collected?
Source:R/null_models.R
null_model_test.RdA model can reach a high AUC by predicting where people record, not
where the species lives. This test compares each metric with its
distribution under a null model in which the "presences" are random
locations drawn with the same sampling bias: the presence predictions
are replaced n_null times by the predictions at as many cells drawn
from pool (with probability proportional to weight, e.g. recording
effort), and the metrics are recomputed against the same absence or
background points. The p-value is the share of null values at least as
good as the observed one.
Usage
null_model_test(
data,
pool,
weight = NULL,
criteria = c(AUC = "max", MAEbal = "min"),
metrics = NULL,
n_null = 499,
n_pool = 20000,
seed = NULL,
rescale = TRUE
)Arguments
- data
A table of evaluation points as for
evaluate_models():obs(1 = presence, 0 = absence or background) and one column of predictions per model.- pool
Predictions at the candidate cells for the random presences: a data.frame with the same model columns (e.g. from
terra::spatSample(models, 10000, na.rm = TRUE)over the calibration area), or the model rasters themselves (terra::SpatRaster), from which up ton_poolcells are sampled.- weight
Sampling weight of the pool cells: a column name of
pool, one value per row, or (with rasters) a raster of recording effort, seegbif_effort_rasters().NULL= uniform.- criteria
Metrics to test and their direction, as in
evaluate_models().- metrics
Optional named list of your own metric functions
function(obs, pred); the optional metricscalibration_slope,calibration_intercept,brierandBoyce_smoothare added when named incriteria.- n_null
Number of null replicates.
- n_pool
Number of cells sampled when
poolis a raster.- seed
Seed.
- rescale
Bring predictions to the 0-1 scale: the scale of each model (0-1, 0-100 or 0-1000) is recognised from its largest value and 0-100 or 0-1000 are divided by 100 or 1000, with a message; see
extract_predictions(). The pool is divided by the same factor as the evaluation data of each model.
Value
A data.frame with one row per model and metric: observed,
null_mean, null_95 (the value reached or bettered by 5% of the
null replicates; for "zero" and "one" criteria, the distance from
0 or 1) and p_value.
Details
Without weight the draws are uniform, which tests only whether the
model separates the records from random cells of the area (the null AUC
is then about 0.5). With recording effort as weight the question is
the stricter and more useful one: is the model better at finding the
species than at finding the places that are visited?
This is a null model of the locations, applied to models that are already fitted, so it works with predictions of any software. It differs from the null models of Raes and ter Steege (2007) and Bohl et al. (2019), which refit the model to each set of random points; those also account for the flexibility of the algorithm and need the modelling software.
Null hypothesis. The model is no better than one whose presences are
random locations from pool, drawn in proportion to weight. With
recording effort as weight, the null keeps the sampling bias of the
records, so a significant result means the model predicts more than where
people record; without weight the random locations are uniform over the
pool, a weaker null for biased records. Significance does not show that
the predictors are the causes of the distribution.
References
Raes, N., ter Steege, H. (2007) A null-model for significance testing of presence-only species distribution models. Ecography 30, 727-736. Bohl, C.L., Kass, J.M., Anderson, R.P. (2019) A new null model approach to quantify performance and significance for ecological niche models of species distributions. Journal of Biogeography 46, 1101-1111.
Examples
sim <- simulate_enm_data(seed = 1)
tab <- extract_predictions(sim$models, sim$presence, sim$absence)
# recording effort that follows the first environmental gradient
effort <- sim$env[[1]]
null_model_test(tab, sim$models, weight = effort, n_null = 99, seed = 1)
#> model metric observed null_mean null_95 p_value
#> 1 Maxent_LQ AUC 0.9797333 0.8838278 0.9197850 0.01
#> 2 Maxent_LQ MAEbal 0.1456401 0.2332487 0.2069291 0.01
#> 3 Maxent_H_rm4 AUC 0.9798000 0.8828985 0.9177800 0.01
#> 4 Maxent_H_rm4 MAEbal 0.2320673 0.2993222 0.2774742 0.01
#> 5 GLM AUC 0.9806667 0.8843167 0.9178067 0.01
#> 6 GLM MAEbal 0.2283786 0.2904986 0.2717393 0.01
#> 7 RandomForest AUC 0.9776667 0.8716086 0.9099117 0.01
#> 8 RandomForest MAEbal 0.2893858 0.3418030 0.3245748 0.01
#> 9 BIOCLIM AUC 0.8209667 0.7027951 0.7454000 0.01
#> 10 BIOCLIM MAEbal 0.4284066 0.4538249 0.4449149 0.01
#> 11 Random AUC 0.4573667 0.4755988 0.5262167 0.80
#> 12 Random MAEbal 0.5212114 0.5122726 0.4870987 0.80
#> 13 GBM AUC 0.9678833 0.8499081 0.8868567 0.01
#> 14 GBM MAEbal 0.2098837 0.2857807 0.2617930 0.01