preENM is a toolkit for data preparation, quality assessment, sensitivity analysis and evaluation throughout ecological niche and species distribution modelling (ENM/SDM). It covers every step before and after fitting, but never fits a model itself: it takes records, rasters and predictions from any software (biomod2, ENMeval, Maxent, tidymodels or your own code), so the same checks apply whatever algorithm you use.
- Before fitting: clean and match the records, delimit the calibration area, compute and compare predictors (climate, terrain, soil), correct sampling bias, and check the design: niche truncation, collinearity, grain, extrapolation.
- After fitting: evaluate, validate and select models, combine them, set thresholds and range metrics, separate the sources of uncertainty in projections, compare niches and report (ODMAP).
- How sensitive is the result? Most steps can be repeated under alternative choices, such as several calibration areas, thinning distances, background strategies, grains or threshold rules, to show how much the conclusions depend on them.
Every result is printed in plain words first, says when something cannot be judged, and states which limits come from the literature and which need more research.
Documentation: https://kkonowalik.github.io/preENM/ (articles, function reference and news), and every function on slides in the function overview.
Installation
Install R (≥ 4.1) from https://cran.r-project.org and, optionally, RStudio from https://posit.co/download/rstudio-desktop/. Then run in R:
install.packages("remotes")
remotes::install_github("kkonowalik/preENM")Some steps use optional packages (e.g. CoordinateCleaner for coordinate tests, geodata for downloads, ggrepel for neater labels in plots); a function that needs one says so and how to install it. To install all of them at once:
remotes::install_github("kkonowalik/preENM", dependencies = TRUE)The workflow at a glance
The manual is on the website, https://kkonowalik.github.io/preENM/, as articles that follow the order of a modelling project; start with Get started, which runs a short workflow on simulated data. Sections 1 to 16 come before fitting: clean the records, delimit the calibration area, prepare the predictors, correct sampling bias and check the design. Then fit the models in the software of your choice. Sections 17 to 28 come after: evaluate, validate and select the models, build maps, judge projections, compare niches and report. Subsections (e.g. 4.3) are steps of their section, and the section numbers below link to them. Every step can also be used on its own.
| Stage | Section | Step | Functions |
|---|---|---|---|
| Before fitting | |||
| Records | 1 | Name matching and point filtering (especially GBIF) |
read_gbif(), match_names(), filter_occurrences(), filter_settings(), filter_layers()
|
| Area | 2 | Accessible area (M): data-derived, adaptive, simulated or from biogeographic regions; several compared as a matter of course |
linking_distance(), linking_stability(), delimit_m(), download_regions(), m_scenarios(), m_simulate(), m_minimal(), m_availability(), plot_m_area(), m_report(), write_m_area()
|
| Area | 3 | Cutting raster files to M |
crop_rasters(), crop_to_m()
|
| Predictors | 4.1 | Climate indices from monthly climatologies (water balance, heat, cold, season, light, bioclim; present, future and past) |
download_chelsa_monthly(), download_chelsa_trace21k(), monthly_files(), climate_indices(), climate_index_names()
|
| Predictors | 4.2 | Composite bioclim variables (bio8, 9, 18, 19) flagged, with smooth substitutes |
climate_index_names(flagged = ), climate_indices()
|
| Predictors | 4.3 | Comparing climate products at the records and across M (agreement, offset, collinearity, map of disagreement) |
climate_source_compare(), plot_climate_sources(), write_climate_sources()
|
| Predictors | 4.4 | Terrain variables from a DEM (slope, aspect, TRI, TPI and DEV at several radii, TWI, heat load) | topo_indices() |
| Predictors | 4.5 | Soil variables from SoilGrids for a region and depth | download_soilgrids() |
| Predictors | 5 | Correlation analysis and variable selection across periods, scenarios and regions |
sample_environment(), select_variables(), best_sets(), recommend_sets(), correlation_by_region(), plot_variable_tree(), plot_correlation(), plot_variable_sets(), write_variable_selection()
|
| Records | 6 | Coordinate uncertainty in environmental terms: keep, propagate (jittered replicates) or drop |
uncertainty_environment(), jitter_uncertainty(), plot_jitter(), write_jitter()
|
| Sampling bias | 7 | One point per raster cell, background points |
merge_occurrences(), thin_by_cell(), sample_background()
|
| Sampling bias | 8 | Environmental thinning, keeping the records’ environmental coverage, thinning by distance, replicate thinning and record weights |
thin_environment(), plot_env_thinning(), write_env_thinning(), thin_distance(), record_weights()
|
| Sampling bias | 9 | Background strategies and recording effort, target-group background, background thickening, effort from accessibility, effort as a covariate, how many background points |
sample_background(method = ), gbif_effort_sql(), gbif_target_group_sql(), download_gbif_effort(), gbif_effort_rasters(), accessibility_effort(), effort_layers(), background_sufficiency(), plot_background_sufficiency(), target_group_check()
|
| Sampling bias | 10 | Aggregation of the records at several grains, and bias-correction sensitivity: thinning and background choices compared |
sampling_aggregation(), bias_sensitivity(), plot_bias_sensitivity()
|
| Design checks | 11 | Niche truncation by M and what to do about it (extend M, donor regions, nested datasets) |
niche_truncation(), niche_coverage(), classify_points(), unfilled_records(), truncation_remedy() and their plots |
| Design checks | 12 | Predictors against random variables |
variable_relevance(), random_variables(), compare_to_random(), coordinate_layers()
|
| Design checks | 13 | Grain sensitivity of records, uncertainty, correlation and the selected variables |
grain_sensitivity(), plot_grain_sensitivity(), write_grain_sensitivity()
|
| Design checks | 14 | Extrapolation risk of projections (ExDet, MOP; disappearing and new conditions) |
extrapolation_risk(), environment_shift()
|
| Design checks | 15 | Final checks: sample size, record years against the climate period; all diagnostics in one report |
check_sample_size(), match_climate_period(), assess_enm_data()
|
| Export | 16 | Data for integrated SDMs (presence-only, presence-absence and counts for intSDM, PointedSDMs or biomod2) |
merge_occurrences(data_type = ), export_integrated(), write_integrated()
|
| After fitting | |||
| Evaluation | 17 | Evaluating and selecting models: any metrics, Pareto front or minimum values, bootstrap |
evaluate_models(), select_models(), plot_pareto(), plot_selection()
|
| Evaluation | 17.3 | Prediction scales checked per model; 0-100 and 0-1000 rescaled to 0-1 |
rescale = TRUE in evaluate_models(), ensemble_models(), … |
| Evaluation | 17.5 | How the selection works (Pareto front, compromise distance, bootstrap robustness) | pareto_rank() |
| Evaluation | 17.6 | Plotting any metrics, zoom on the best models, 3-D |
plot_models(), plot(sel)
|
| Evaluation | 18.1 | Calibration (reliability diagram, calibration slope and intercept, Brier decomposition) |
calibration_curve(), brier_decompose(), brier_score(), plot_calibration()
|
| Evaluation | 18.2 | Boyce index with few presences (smoothed P/E curve, bootstrap interval) |
boyce_index(smooth = , n_boot = ), plot_boyce()
|
| Evaluation | 18.3 | Plausibility of response curves |
response_check(), plot_response_check()
|
| Evaluation | 18.4 | Stability of variable importance across algorithms, runs and regions |
importance_stability(), plot_importance_stability()
|
| Validation | 19 | Cross-validation: spatial or environmental folds, hold-out metrics |
suggest_block_size(), spatial_folds(), environmental_folds(), evaluate_cv()
|
| Validation | 19.1 | Auditing the folds (leakage, separation, spatial sorting bias) |
fold_report(), plot_folds(), spatial_sorting_bias()
|
| Validation | 19.2 | Other fold designs (buffered, groups, periods, shifted blocks), how much the evaluation depends on the design, geographic-distance null |
buffer_exclusion(), group_folds(), temporal_folds(), cv_sensitivity(), plot_cv_sensitivity(), geographic_null()
|
| Validation | 19.3 | Validation with fossil records (hindcasts) |
temporal_validation(), download_neotoma(), neotoma_records(), calibrate_radiocarbon(), age_slice_weights(), fossil_site_bins(), site_bin_slices()
|
| Validation | 20 | Significance against sampling bias | null_model_test() |
| Maps | 21 | Ensemble of the selected models and the disagreement between them; the methods compared |
ensemble_models(), plot_ensemble(), plot_ensemble_pca(), ensemble_scenarios()
|
| Maps | 22 | Thresholds under several rules and the cells on which they agree |
thresholds(), threshold_agreement(), plot_thresholds()
|
| Maps | 23 | Range metrics (EOO, AOO, locations, fragmentation) per threshold rule, change, IUCN thresholds |
range_metrics(), plot_range_metrics(), write_range_metrics()
|
| Projections | 24 | Design bias of projections (models of random points with the records’ sampling bias) |
null_occurrences(), transfer_bias_test(), plot_transfer_bias()
|
| Projections | 25 | Partitioning projection uncertainty (GCM, scenario, algorithm, run) |
partition_uncertainty(), plot_partition()
|
| Projections | 25.1 | Spread due to coordinate error, compared with the disagreement between models |
coordinate_spread(), plot_coordinate_spread()
|
| Projections | 26 | Maps of biogeographical ignorance from recording effort, joint map with suitability |
ignorance_map(), record_ignorance(), taxon_complexity(), plot_ignorance()
|
| Comparison | 27 | Niche overlap between species, lineages or cytotypes, and its sensitivity to methodological choices |
niche_overlap(), overlap_scenarios(), plot_niche_overlap(), prediction_overlap()
|
| Reporting | 28 | Reporting (ODMAP protocol filled from the workflow) | odmap_table() |
| With biomod2 | article | preENM’s records, background sets, predictors and folds as biomod2 arguments; biomod2’s predictions and variable importance back into preENM | to_biomod2() |
Inputs can be GeoTIFF paths, terra rasters, CSV files or sf objects. Points are re-projected to each raster automatically.
Every figure can be saved by the function that draws it: add file = "figure.pdf" (or .png, .jpeg, .tiff, .svg), file = c("figure.png", "figure.pdf") for several formats, or a name without extension (file = "figure") for both PNG and PDF; width and height set the size in pixels (e.g. width = 2100, height = 1500; PDF and SVG files get the same size at 300 pixels per inch). The plot is still returned and can be changed further with ggplot2.
How much does the result depend on your choices?
Many steps rest on a choice that the data do not settle. For each of them preENM runs the step under the reasonable alternatives and reports how much the result changes, and whether the conclusion stays the same. Together these sensitivity analyses are what preENM adds to the modelling software; report them with the result. When a step was run under alternatives, its printout ends by naming the choice it tests, and ?sensitivity_analyses lists them all. Choices that only fitted models can judge, such as the predictor set or model settings, are compared after modelling (more).
| Choice | Function | Section |
|---|---|---|
| Filter thresholds for the records | filter_sensitivity() |
1 |
| How M is delimited and how far it extends; what L rests on |
m_scenarios(), m_minimal(), linking_stability()
|
2 |
| The climate data product | climate_source_compare() |
4.3 |
| Where imprecise records really lie |
jitter_uncertainty(), coordinate_spread()
|
6, 25.1 |
| Which records survive thinning |
thin_distance(n_rep = ), thin_environment(n_rep = )
|
8 |
| The number of background points | background_sufficiency() |
9 |
| The thinning and background design | bias_sensitivity() |
10 |
| The margin that defines the edge of M | niche_truncation(edge_check = ) |
11 |
| The grain of the rasters | grain_sensitivity() |
13 |
| The evaluation points behind the ranking of models | evaluate_models(n_boot = ) |
17.5 |
| Algorithm, run and region behind variable importance | importance_stability() |
18.4 |
| The cross-validation design | cv_sensitivity() |
19.2 |
| How the ensemble is built | ensemble_scenarios() |
21 |
| The threshold rule |
thresholds(), range_metrics()
|
22, 23 |
| Data versus study design in a projected change | transfer_bias_test() |
24 |
| Data, algorithm, climate model and scenario | partition_uncertainty() |
25 |
| Background and space of a niche comparison | overlap_scenarios() |
27 |
How preENM is tested
Every function has unit tests with known answers, including the published equations of the indices and metrics. The validation/ folder of the repository holds simulation studies of the methods with known truth (the linking-distance M, environmental thinning, extrapolation diagnostics with a clustered reference, the handling of wrong inputs) and their results, including the conditions in which the methods fail; see validation/README.md.
Citation
The package is still under development. You can use it but some functions may be upgraded or added in near future. Therefore we do not have a formal publication desribing the package yet. But if you wish to use it, especially if you use the model-selection method, please cite the paper (citation("preENM")):
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. https://doi.org/10.1038/s41598-020-80062-1 (free to read: https://rdcu.be/cjB5b)
Depending on the module you use, preENM relies on several other R packages - such as terra, CoordinateCleaner, ggplot2 and others. Please cite these underlying packages in your work as well. Additionally, most functions are based on published methodologies, so we recommend citing the original papers too.
Thanks and good luck with modelling!
