biomod2 (Thuiller et al. 2009, Ecography 32, 369-373) fits, evaluates and projects species distribution models with many algorithms. preENM fits nothing: it prepares the data before biomod2 and judges the results after it. The two meet at three points, and at each one preENM’s output is used by biomod2 without conversion by hand.
| Step | preENM | biomod2 |
|---|---|---|
| Records |
filter_occurrences(), thin_by_cell(),
thin_environment(), thin_distance()
|
resp.var, resp.xy
|
| Accessible area and predictors |
delimit_m(), crop_to_m(),
select_variables()
|
expl.var |
| Background (pseudo-absences) |
sample_background() with n_sets (uniform,
effort, target group, thickening) |
PA.strategy = "user.defined",
PA.user.table
|
| Folds |
spatial_folds(), environmental_folds(),
group_folds(), temporal_folds()
|
CV.strategy = "user.defined",
CV.user.table
|
| Predictions |
evaluate_models(), select_models(),
ensemble_models(), thresholds(),
range_metrics(), extrapolation_risk()
|
get_predictions() |
| Variable importance | importance_stability() |
get_variables_importance() |
Before biomod2: the data design
to_biomod2() turns the records, background sets,
predictors and folds into the arguments of
BIOMOD_FormatingData() and BIOMOD_Modeling().
Each background set of sample_background(n_sets = ) becomes
one pseudo-absence set, and each fold one cross-validation run, repeated
for every pseudo-absence set. The folds can be given as a function of
the points table, so that they are made for the same points biomod2
receives.
library(preENM)
library(biomod2)
env <- crop_to_m(env, m) # predictors cut to M
pres <- thin_by_cell(records, env) # one record per cell
bg <- sample_background(env, n = 10000, n_sets = 3, method = "effort",
effort = effort, seed = 1)
b2 <- to_biomod2(pres, env, background = bg, resp_name = "species",
folds = function(p) spatial_folds(p, k = 4,
block_size = 100, coords = c("x", "y"), seed = 1))
b2 # what biomod2 will get
dat <- do.call(BIOMOD_FormatingData, b2$formating)
mod <- do.call(BIOMOD_Modeling,
c(list(bm.format = dat, modeling.id = "preENM",
models = c("GLM", "GAM", "RF", "MAXNET"),
var.import = 3, CV.do.full.models = FALSE),
b2$modeling))The pseudo-absence table holds, in each set, all presences and
absences plus the background points of that set; the cross-validation
table marks the calibration rows (TRUE) of each run, with
column names in biomod2’s format (_PA1_RUN1, …). Points
without values in all predictors are left out, as biomod2 would.
After biomod2: predictions into preENM
biomod2’s projections are rasters on a 0-1000 scale; preENM reads them directly and rescales them. Evaluate them on independent data where you have it (here true absences of a survey), and select models by the Pareto front of AUC and MAE as in the article on evaluation:
proj <- BIOMOD_Projection(bm.mod = mod, proj.name = "current",
new.env = env, models.chosen = "all")
pred <- get_predictions(proj) # one layer per model run
ev <- evaluate_models(pred, survey_presences, survey_absences,
data_type = "absence")
sel <- select_models(ev, rule = "both")
plot_pareto(ev)
The selected models then go to the rest of preENM: an ensemble and
the disagreement between models (ensemble_models()),
thresholds and range metrics (thresholds(),
range_metrics()), where projections extrapolate
(extrapolation_risk()) and how much a projected change owes
to the study design (transfer_bias_test()).
best <- pred[[sel$model[sel$selected]]]
ens <- ensemble_models(best)
tab <- extract_predictions(best, survey_presences, survey_absences)
thr <- thresholds(tab)Variable importance across runs
biomod2 measures the importance of each variable in every run.
Whether the order of the variables holds across algorithms,
pseudo-absence sets and folds is the question of
importance_stability():
vi <- get_variables_importance(mod)
st <- importance_stability(vi, variable = "expl.var", value = "var.imp",
algorithm = "algo", run = "full.name")
st
plot_importance_stability(st)Notes
- biomod2 reports its own evaluation on the cross-validation folds. preENM evaluates the same predictions on any points you give, with any metrics, and selects by the trade-off between them; with independent absences this is the stronger test.
- The folds of preENM can be audited before modelling
(
fold_report(),plot_folds()) and compared after it (cv_sensitivity()). -
to_biomod2()needs no biomod2 to run: it returns lists of arguments. The formats follow biomod2 4.x.
