Niche truncation by M, predictors against random variables, grain, extrapolation, final checks and data for integrated models.
11. Checking that the niche is not truncated by M
A model learns only the part of a species’ response that the
calibration area contains. If the records are still frequent where the
conditions of M end, the limit of the niche lies outside M, and a
projection to conditions beyond M extrapolates a curve whose end was
never seen. niche_truncation() checks every predictor at
both ends:
tr <- niche_truncation(occ, env_m,
projections = list(lgm = env_lgm, ssp370 = env_2070))
tr
plot_niche_truncation(tr)
-
edge_low,edge_high: how often records fall in the outer 5% of M’s conditions, relative to how common those conditions are in M (0 = the species avoids the margin, so its limit is inside M; 1 or more = it uses the margin at least as often as M offers it:truncated_*). -
gap_low,gap_high: the distance between the most extreme record and the limit of M, as a share of M’s range. - For each projection, the share of cells beyond M and beyond the
records, and
risk_low/risk_highwhere a truncated end is exceeded. - The 5% margin is a screening choice: the diagnosis is repeated at
margins of 1%, 2.5%, 5% and 10% (
edge_check), and the printout says whether a truncated end is found at every margin or only at some (edge_stability). Records crowding at a limit can also come from sampling bias near it: giveeffort(a recording-effort raster) and each end getseffort_low/effort_high, the effort in the margin relative to M, with a reading: truncation at an intensely recorded margin is weaker evidence, and a margin without records that was barely recorded may still be truncated.
For a flagged variable, consider a larger M, another variable, or clamping and a cautious reading of the projection. The flags are a screening aid: a species may truly live up to a coast or a mountain crest where M ends, and sampling bias near an edge inflates them, so use thinned records.
Modelling a widespread species in one region: is a nested
model needed? Many studies model a species only in a region of
interest, e.g. one country, although it lives far beyond. The regional
model then learns only the conditions the species meets there, which is
the truncation above caused by the borders of the study rather than by
M. Spatially nested (hierarchical) models combine a model of the whole
range, often coarser, with the regional one (e.g. the regional model
gets the whole-range model as a covariate, or the two are multiplied).
In 108 tree species of Spain and Switzerland, they removed truncation
and extrapolation and predicted better than regional-only models
(Goicolea et al. 2025, Ecography e07328). Whether you need one
depends on how much of the niche your region contains.
niche_coverage() measures this from records of the whole
range (e.g. GBIF) and layers covering it:
nc <- niche_coverage(occ_whole_range, env_whole_range, region = country,
log_vars = "auto", # log1p of precipitation amounts
file = c("niche_coverage.png", "niche_coverage.pdf"))
nc # results, statistics, advice
plot_niche_coverage(nc) # niche space and map side by side
unfilled_records(nc) # records in the unfilled niche, to check
# with a separate regional data set (e.g. a national survey), the usual
# case for nested models
nc <- niche_coverage(occ_whole_range, env_whole_range, region = country,
region_points = occ_national)Large global layers (e.g. 30 arc-second CHELSA) are fine: the
function reads values only at the records and at random locations in the
region (n, default 100,000), so memory does not grow with
the size of the rasters.
The records and the layers must cover the whole range of the species. Records outside the layers have no values and are left out; the function says how many. If only the records of the region remain (e.g. the layers were cut to M, or the records are those already thinned within M), the region trivially contains their niche: the function warns and the advice reads “cannot be judged”. The region itself can be a country or the M of the regional model.

| Result | Meaning |
|---|---|
unfilling |
share of the species’ niche without a regional record, the measure of Goicolea et al. (2025): the space of the first two principal components is cut into cells, the niche is the cells holding whole-range records, and each cell counts once however many records it holds |
not_available |
share of the niche cells whose conditions do not occur in the region at all; no regional model can learn them |
unfilling_records,
not_available_records
|
the same counted by records; for comparison only (see below) |
per variable: coverage, outside_records,
outside_region
|
part of the variable’s range covered by the regional records, and the share of whole-range records beyond the regional records and beyond the region’s conditions |
unfilling_lo, unfilling_hi
|
bootstrap 95% interval of unfilling (resampled
records) |
unfilling_null, unfilling_ses,
unfilling_p
|
the unfilling a random sample of the whole-range records of the size of the regional records would leave, and how far the region’s value is beyond it |
| robustness tables |
unfilling when a niche cell needs 1, 2, 3 or 5 records,
and with a coarser and a finer grid; the printout gives the resulting
range |
advice |
graded by unfilling
(limits = c(0.1, 0.25, 0.5)): small gap, regional model
sufficient; moderate gap, a nested model worth considering for
projections; large gap, nested model advised; very large gap (above 50%,
“very poorly filled” in Goicolea et al. 2025, the only limit taken from
the paper), strongly advised; “cannot be judged” if all records lie in
the region |
How serious is the gap? The bootstrap interval says how much the unfilling depends on the particular records. The null comparison separates two causes: if the region leaves much more of the niche unfilled than a random sample of the same number of whole-range records would (large SES, small p), the region lacks conditions of the niche; if not, the gap is about what its number of records alone would leave, and more regional records may close it.
Sparse records and the grid. One record in a remote
cell counts as much as a thousand in another, so a handful of outliers,
records of a related taxon or wrong coordinates can decide the advice.
The printout gives the unfilling when cells need 2, 3 or 5 records and
with a coarser and a finer grid, and sums it up as a range, e.g. “19% to
36%: from a moderate to a large gap”; unfilled_records()
lists the records in unfilled cells with their coordinates so you can
map and check them. The grid is 20 x 20 cells by default and coarser
with fewer than about 1,200 records, so that occupied cells hold several
records on average (n_bins to set it).
Why niche cells and not records. Regions of interest are usually the best-sampled part of a range. If 93% of the records come from the region, the share of records in the unfilled niche can never exceed 7%, even if the other 7% reveal a large part of the niche: a broad niche known from few records elsewhere would hardly count, and the advice would wrongly say that a regional model is enough. Counting each occupied cell of environmental space once removes this dependence on sampling effort. The printout gives both, and the plot frames the unfilled niche cells in red. Per variable, the shares are smaller than in the niche, because a record can lie within the range of every single variable but in a combination of conditions that the region lacks.
If unfilling is much larger than
not_available, the missing conditions exist in the region
but the species has no records there (absent, undersampled or limited by
other factors), which a nested model does not solve by itself. Then run
niche_truncation() on the regional calibration area to see
along which predictors and at which end the response is cut.
What a nested model adds to projections. A model of
the whole range knows conditions that the regional records lack. A
species common across Europe and modelled only in Poland, for example:
as Poland becomes warmer, its future conditions leave the Polish niche,
and a regional model predicts losses, although the species lives in such
conditions further south. The whole-range model does not predict those
losses. This assumes that the regional populations can live in the
conditions of the populations elsewhere (or be replaced by them); strong
local adaptation would make the nested model too optimistic.
classify_points() shows how much of the region is in that
situation: it places any points in the same niche space, e.g. the region
under a future (or past) climate, evaluation sites or fossil sites.
Projected conditions in cells known only from elsewhere are where the
nested model changes the prediction. With predicted
(whether your regional model predicted each point as suitable), it
counts the misses per category:
fut <- terra::spatSample(env_2070_region, 5000, na.rm = TRUE) # or values at sites
cl <- classify_points(nc, values = fut)
cl # share of points per category
cl <- classify_points(nc, values = site_values, predicted = suitable)
cl # where the misses are| Category | Meaning for a nested model |
|---|---|
filled |
conditions known from regional records: a nested model adds nothing; misses here come from the model, the variables or the records |
elsewhere, available /
elsewhere, absent
|
conditions known only from records outside the region (occurring in the region today, or not): a nested model can help |
region only, available, unoccupied,
unoccupied
|
conditions with too few or no records of the species anywhere |
outside |
beyond all conditions the species is known from: extrapolation for any model |
New values must be in the units of the layers used in
niche_coverage(); points that land far beyond the whole
range in the niche space, or variables with a median far from that of
the records (e.g. Kelvin against degrees Celsius), give a warning.
Acting on truncation. Ignoring truncation is costly:
models lose accuracy when transferred over distance and with
extrapolation (Rousseau & Betts 2022, Ecography e06060),
when the niche has changed (Liu et al. 2022, Ecology 103,
e3719), and in invaded ranges (Nguyen & Leung 2022, Global
Ecology and Biogeography 31, 1051-1065).
truncation_remedy() takes the result of
niche_truncation(), the records, layers that reach beyond M
and M itself, and proposes a remedy for each truncated end:
- Extend M when the missing conditions are adjacent: the band of conditions just beyond M’s limit (a quarter of M’s range, with the other variables within the records’ range) begins next to M, and a modest extension towards it (at most three times M’s area) samples every part of the band. The printout says how far and how much larger.
- Integrate donor regions when the conditions occur only farther away: regions where they do, with their distance and the ends they supply, so that you can look for records there and combine the data (Chevalier et al. 2021, Ecological Applications 31, e02427).
- Accept the truncation, and state it, when the conditions occur nowhere in the layers (e.g. only in a future climate): projections into them extrapolate.
It also prepares a spatially nested design: a parent dataset
(records of the whole range, parent_records, within the
extended extent and the donor regions, to be modelled at a coarser
resolution with climatic variables) and a child dataset (the
records in M at full resolution). Fit the parent first, project it onto
the child’s grid, and use the projection as a covariate of the child
model, or multiply the two predictions (geometric mean); the covariate
strategy was the more accurate (Goicolea et al. 2025).
rem <- truncation_remedy(tr, occ, env_europe, m,
parent_records = gbif_whole_range)
rem # remedy per truncated end, in plain words
plot_truncation_remedy(rem) # M, the extension, the donor regions
write_truncation_remedy(rem, "nested") # parent/child CSV, extents, READMEIs the nested or extended model actually better for the region? Test
both on independent regional records (e.g. a survey, or a spatial fold
that the models did not see): extract the predictions of the regional
and the whole-range (or nested) model at those points and compare them
with evaluate_models(). If local adaptation is possible, a
whole-range model can be worse in the region even when it looks better
elsewhere.
# predictions of both models, as SpatRaster layers named after the model
evaluate_models(c(regional = pred_regional, nested = pred_nested),
presence = survey_presences, absence = survey_absences,
data_type = "absence")12. Are the selected predictors better than random variables?
A set of uncorrelated predictors can still hold layers that mean nothing to the species. The test of Konowalik (2022) answers this by modelling the predictors together with random variables and removing those that are no more important than the random ones (Konowalik, K. (2022) Phylogeography and colonization pattern of subendemic round-leaved oxeye daisy from the Dinarides to the Carpathians. Scientific Reports 12, 16443. https://doi.org/10.1038/s41598-022-19619-1). preENM offers it in two forms.
Before any modelling.
variable_relevance() compares, for each layer, the values
at the records with the values available in the calibration area
(Kolmogorov-Smirnov distance D), and asks how often a
random layer reaches the same distance at the same records:
rel <- variable_relevance(occ_thinned, env, n_null = 499)
rel
#> layer D null_mean null_95 p_value relevant shift_sd breadth_ratio
#> temperature 0.458 0.190 0.311 0.002 TRUE 0.705 0.459
#> rainfall 0.290 0.179 0.319 0.080 FALSE -0.306 0.478
#> slope 0.063 0.185 0.310 0.995 FALSE -0.029 0.911The random layers are not white noise. Real layers are smooth and
records are clustered, so a meaningless smooth layer differs from the
background at the records far more than noise does (Fourcade et al. 2018
predicted distributions from paintings). The null layers therefore have
the spatial structure of the real one: null = "field" draws
smooth random surfaces with the same autocorrelation range (any shape of
M), null = "shift" moves the layer itself around the raster
(torus translation, Harms et al. 2001; faster and exact, for an M that
fills most of the rectangle). null = "noise" is the classic
random variable without spatial structure (the layer’s values shuffled
among the cells); it is there for comparison and nearly every layer
passes it. shift_sd and breadth_ratio say how
the species responds: its optimum is shifted from the mean of the area,
or its niche is narrower than the area.
It is a screen and it has limits: it looks at one layer at a time (an interaction can be missed), a layer correlated with a true driver passes too, recording bias along a layer looks like a response (use thinned records), and a layer that is one gradient across the whole area cannot be told apart from geography.
With cross-validation, run it within the folds. The
test uses the records, so dropping layers because of it is feature
selection on the response. If the models are later cross-validated,
selection on all records lets the test records influence the models, a
common form of data leakage (Stock et al. 2023, Table 1): run it on the
training records of each fold. Collinearity screening with
select_variables() does not use the records and can be done
once.
Inside the models, with any software.
random_variables() writes random layers to add to the
predictors. Each takes the values of one real layer (same distribution,
same empty cells) and arranges them in smooth random patches of the same
size as in the real layer; method = "shuffle" gives the
classic white-noise variable.

rnd <- random_variables(env, n = 5, seed = 1, filename = "random.tif")
# fit your models with c(env, rnd), several algorithms and runs, and
# collect the importance of every variable in a long table
keep <- compare_to_random(importance, variable = "variable",
value = "importance", algorithm = "algorithm",
run = "run")
keep
#> variable Maxent GLM RF GBM GAM algorithms mean_importance keep
#> temperature 1.0 1.0 1.0 1.0 1.0 5 41.2 TRUE
#> rainfall 0.8 0.4 1.0 0.6 0.2 3 12.9 TRUE
#> slope 0.0 0.2 0.4 0.0 0.0 0 2.1 FALSEThe columns of the algorithms give the share of runs in which the
predictor was more important than the best random variable
(threshold = "max"; a number such as 0.95 uses
that quantile of the random variables instead, which is less dependent
on how many there are). A predictor is dropped only when most algorithms
do not support it. Remove those, make new random variables, fit again,
and repeat until every predictor is kept, because importance is shared
among predictors and changes when one is removed.
A third reference is geographic position itself: fit the models with
coordinate_layers(env) as well, and
compare_to_random(..., coordinates = "^coord_") adds
beats_coordinates, the share of runs in which each
predictor is more important than the coordinates. A predictor that is
not may stand in for geography rather than for the environment.
13. Does the design depend on the grain?
The grain (cell size) of a model is usually whatever resolution the
rasters happen to have, yet spatial scale and resolution can change the
conclusions of distribution models (Henderson et al. 2023), and how well
suitability predicts local abundance depends on grain and on the scale
of the covariates (Brambilla et al. 2023; Ferrer-Ferrando et al. 2025).
grain_sensitivity() repeats the preparation at a series of
coarser grains and reports how the design changes. At each grain it:
- aggregates the layers on disk with GDAL, one grain at a time (as
crop_rasters()does), to the mean of the native cells, in floating point so that averages of integer layers are not rounded; - keeps one record per cell (
thin_by_cell(), section 7) and thins the records in environmental space (thin_environment(), section 8); - counts the records whose coordinate uncertainty spans too much of
the niche at that grain (
uncertainty_environment(), section 6); - samples the layers and runs the variable selection
(
sample_environment(),select_variables(), section 5).
g <- grain_sensitivity(records, list(present = now, LGM = lgm),
factors = c(1, 2, 4, 8), sizes = 3:6, seed = 1)
g # IN SHORT: up to which grain the set is stable
plot_grain_sensitivity(g, file = "grain_sensitivity")
write_grain_sensitivity(g, "grain")The printout starts with the practical answer: the coarsest grain at
which the selected variable set (the top-ranked set of size
variables) is still the same as at the finest grain. Agreement between
grains is measured with the Jaccard index of the selected sets and of
the collections of passing sets; the latter is safer when several sets
share the top rank. The table also gives the records kept after cell and
environmental thinning, the share of records too uncertain for the
grain, the number of collinear pairs and the mean change of Spearman
rho. Give the periods or scenarios of the projections as data sets, as
in your own selection, so that novelty and gradient stability rank the
sets too. A record that sits near the edge of a coarse cell may span two
cells with different values, so the share of records too uncertain can
rise as well as fall with grain.

Grain is a choice about the ecology (the scale at which the species responds) and the data (the positional accuracy of the records); the stable range is the room within which to make it. Treat “stable” (by default the same set) as a preENM default, not a published limit.
14. Mapping where a projection extrapolates
niche_truncation() answers per variable;
extrapolation_risk() maps it, so that predictions in novel
conditions can be masked or read with care:
ex <- extrapolation_risk(reference = env_m, projection = env_2070)
terra::plot(ex[[c("nt1", "nt2", "mop")]])
novel <- ex$nt1 < 0 | ex$nt2 > 1 # outside a range, or a new combination
nt1 (ExDet) is 0 inside the range of every variable and
negative outside; nt2 above 1 marks combinations of values
that the calibration data lack although each value is within range,
which range checks and MESS miss; mop grades similarity to
the nearest tenth of the calibration data; n_outside and
most_novel say how many variables are out of range and
which is the farthest. reference can also be a table of the
values at the records and background points used for fitting. Prefer an
even sample of M (the rasters, or the background points) over the
records alone: with a reference clustered like biased records, MOP
distances nearly doubled in a simulation
(validation/validate_mop.R), while the novelty flags of
ExDet hardly changed.
environment_shift() gives the summary in numbers, in
both directions: how much of the present environment of the study area
is gone in the projection, and how much of the projection is new
(Williams et al. 2007).
environment_shift(env_m, list(period_2 = env_p2, period_3 = env_p3))
#> projection variable shift_sd disappearing novel
#> period_2 bio01 1.04 0.30 0.30
#> ...
#> - period_2: 30% of present cells have conditions that disappear and 30%
#> of projected cells have new ones. Expect a predicted decline that
#> does not depend on the records; ...The disappearing share matters as much as the new one: a model can only call suitable what it saw during training, so when present conditions disappear, most methods predict a decline for any species (section 24).
Novelty is not the same as uncertainty: a novel cell can get similar predictions from all models, and models can disagree in familiar conditions. Model disagreement is mapped in section 21 and its sources separated in section 25.
15. Final checks: sample size and climate period
check_sample_size(occ_thinned, env, k = 5) # enough records? per predictor? per fold?
occ <- match_climate_period(occ, c(1981, 2010)) # records from the period of the climate data?check_sample_size() counts occupied cells and compares
them with the minimum numbers of van Proosdij et al. (2016; 14 for
narrow-ranged, 25 for widespread species), with 10 records per predictor
and with 5 per fold. match_climate_period() adds
period_match (within, before,
after, unknown) and
years_outside, and prints the counts.
assess_enm_data() gathers the diagnostics you ran into
one table: for each, the area of the data, a status (ok, review, issue
or info), the finding and what to do. Each status is the verdict of the
function that made the result; there is deliberately no overall score,
and a diagnostic that was not run is absent, not “ok”.
assess_enm_data(sample_size = ss, m = m, l_stability = st,
truncation = tr, predictors = sel, background = bs,
target_group = tg, aggregation = sa)16. Preparing data for integrated models
Integrated species distribution models combine presence-only records, presence-absence surveys and counts in one model, each with its own observation process (Zulian et al. 2021, Diversity and Distributions 27, 2498-2509; Morera-Pujol et al. 2023, Ecography e06451). For data-deficient, narrow-ranged species, integration improved models compared with presence-absence data alone, though only slightly, and more clearly compared with presence-only data (Makinen et al. 2026, Diversity and Distributions e70157). preENM does not fit them; it prepares their input, keeping track of the kind of data each record is from merging to export.
-
Merge with a data type per source.
merge_occurrences()addsdata_type("presence_only","presence_absence","abundance"or your own label) andresponse(1 for presences, 1/0 for surveys, the count otherwise; read fromoccurrenceStatus,present,individualCountor a column you name). Presence-only records whoseoccurrenceStatusisABSENTare reported. -
Filter each type with its own settings.
filter_occurrences()takes a list of settings named by data type: a structured survey need not pass the coordinate-precision tests meant for herbarium records. Absences are exempt from the tests that judge whether a presence is plausible (range, isolation, climate limits).filter_report()gives one column per data type andrecord_fate()shows the type and response of each record. -
Export.
export_integrated()returns one dataset per data type (or per source,split = "source") in the structure the modelling package expects, with no dependency on it.
occ <- merge_occurrences(GBIF = gbif, herbarium = specimens, survey = plots,
counts = transects,
data_type = c(survey = "presence_absence",
counts = "abundance"))
st <- list(presence_only = filter_settings("strict"),
presence_absence = filter_settings("lenient",
drop_tests = c("coarse_decimals",
"grid_cell_centre")),
abundance = filter_settings("lenient"))
res <- filter_occurrences(occ, st, layers)
filter_report(res) # outcomes per data type
ex <- export_integrated(res, "PointedSDMs", split = "source",
crs = "EPSG:3035")
ex # datasets, prevalence, warnings
# PointedSDMs::startISDM(ex$export$data, Projection = ex$export$args$Projection,
# responsePA = "present", responseCounts = "counts", ...)| Format | What you get |
|---|---|
"intSDM" |
per dataset, the arguments of $addStructured():
dataStructured (sf), datasetType
("PO", "PA", "Counts"),
responseName, trialsName,
speciesName, datasetName;
do.call(workflow$addStructured, d)
|
"PointedSDMs" |
data: named sf objects, presence-absence
with column present, counts with counts,
presence-only without a response column (how PointedSDMs recognises
them); args: responsePA,
responseCounts, trialsPA,
Projection, speciesName
|
"biomod2" |
per dataset and species, the arguments of
BIOMOD_FormatingData(): resp.name,
resp.var, resp.xy, data.type
("binary", "count", "abundance");
biomod2 models each data type separately rather than integrating them
(Gueguen et al. 2026, Ecography e08588) |
"generic" |
data.frames with species, x,
y, response, data_type,
source
|
The printout warns about presence-absence datasets without absences
(they cannot inform a presence-absence likelihood), extreme prevalence
and small datasets; write_integrated() saves one CSV per
dataset. Thin presence-only data with thin_by_cell() per
data type, not across types: a survey absence and an opportunistic
presence in one cell are both information.
