Many studies model a widespread species only in a region of interest, e.g. a country. A model calibrated there learns only the conditions the species meets in that region. If the species also lives in conditions that the region lacks or where it has no records, the response curves are truncated, and projections (to the future, or to warmer or drier parts of the region) extrapolate. Spatially nested (hierarchical) models address this by combining a model of the whole range, often at a coarser resolution, with the regional model (Pearson et al. 2004; Mateo et al. 2019; Chevalier et al. 2021; Goicolea et al. 2025). This function tells you how much a regional model would miss, from the records of the whole range and layers covering it.
Arguments
- points
Records of the whole range (data.frame, CSV path,
sfor terra::SpatVector).- env
Layers covering the whole range (terra::SpatRaster or files).
- region
The region of interest: polygons (
sf,SpatVector, file) or a raster (cells with values), e.g. a country or the M of a regional model.- region_points
Optional regional records from another source, e.g. a national survey (the usual case for nested models, where the regional model uses more precise regional data). Then
unfillingand the per-variable values compare these withpoints; by default the records ofpointsthat fall inregionare the regional records.- log_vars
Variables log-transformed (
log1p) before the PCA, e.g. skewed precipitation amounts: names,"auto"for bioclim precipitation amounts recognised by name (bio12-14, bio16-19), orNULL(default) for none.- probs
Quantiles of the whole-range records that define their range per variable (default the central 98%, so that a few outliers do not decide it).
- n_bins
Number of bins per principal component, or
"auto"(default): 20, coarser with fewer than about 1,200 records (at least 8), so that occupied cells hold several records on average. The printout also gives the unfilling for a coarser and a finer grid.- min_records
Records a cell needs to count as part of the niche; e.g. 2 ignores cells with a single, possibly erroneous record.
- limits
Three
unfillingvalues separating a small gap ("regional model sufficient"), a moderate one ("nested model worth considering"), a large one ("nested model advised") and a very large one ("nested model strongly advised"). preENM defaults, except 50%, "very poorly filled" in Goicolea et al. (2025).- n_boot, n_null
Bootstrap resamples and random samples for the statistics (0 to skip).
- n
Number of cells sampled from the region.
- coords, points_crs
Coordinate columns and CRS of
points.- seed
Seed for the cell sample and the statistics.
- file
Optional file(s) to save the plot to (see
plot_niche_coverage()), e.g.c("coverage.png", "coverage.pdf").- width, height
Size of the saved figure in pixels (PDF and SVG at 300 pixels per inch).
Value
A niche_coverage object: a list with summary (records,
niche_cells, unfilling with unfilling_lo/unfilling_hi,
unfilling_null, unfilling_ses, unfilling_p, not_available,
the record-based shares and advice), robustness (unfilling for
several min_records), variables (one row per layer), bins (one
row per cell with records: centre, records, regional records, regional
density percentile, category), records (the whole-range records with
coordinates and category, see unfilled_records()) and what
classify_points() and plot_niche_coverage() need.
Details
The niche. The records of the whole range are placed in the space of
the first two principal components of the variables (after log_vars
are log-transformed), which is cut into n_bins x n_bins cells. The
niche is the cells holding at least min_records whole-range records;
every cell counts once, however many records it holds, so that the
well-sampled region does not dominate.
unfilling: the share of the niche cells without a regional record, the measure used by Goicolea et al. (2025).not_available: the share of the niche cells whose conditions do not occur in the region at all. No regional model can learn these; they matter when the region moves into them (e.g. under warming).unfilling_records,not_available_records: the same counted by records. They can never exceed the share of records outside the region, so with a well-sampled region they understate the gap; given for comparison only.Per variable: the part of the range of the whole-range records covered by the regional ones (
coverage), and the shares of whole-range records beyond the range of the regional records (outside_records) and beyond the conditions of the region (outside_region).
How serious is the gap? Two statistics, both in the printout:
A bootstrap interval of
unfilling(n_bootresamples of the records): how much it depends on the particular records.A null comparison: the unfilling left by random samples of the whole-range records of the same size as the regional records (
n_nullsamples). If the region leaves much more unfilled than a random sample of the same size (largeunfilling_ses, smallunfilling_p), the gap comes from the conditions of the region, not from its number of records.
Robustness. Single records in remote cells (outliers, other taxa,
errors) can drive unfilling. The printout gives it for min_records
1, 2, 3 and 5 and says when the advice changes; check the records in
unfilled cells with unfilled_records() (e.g. their taxonomy).
Advice (from unfilling and limits), graded: below 10% a small
gap (a regional model sees nearly the whole niche); 10-25% a moderate gap
(a nested model worth considering for projections); 25-50% a large gap
(nested model advised); above 50%, "very poorly filled" in Goicolea et
al. (2025), a very large gap (strongly advised). Only the last limit is
from the paper. A nested model matters most for projections: future (or
past) conditions of the region that lie outside the regional niche but
inside the conditions the species occupies elsewhere; a regional model
predicts losses there that the whole-range model does not.
classify_points() shows how much of the region is in that situation.
This assumes no strong local adaptation of the regional populations.
Related. niche_truncation() detects truncation from the records of
the region alone (do they crowd against the limits of M?);
truncation_remedy() then locates the missing conditions (adjacent to
the region or in donor regions) and prepares the parent and child
datasets of a nested model.
Memory. Values are read only at the records and at n random
locations in the region, so large (e.g. global 30 arc-second) layers can
be used.
The records and layers must cover the whole range. Records outside
the layers have no values and are left out (their number is reported);
if only the regional records remain, the region trivially contains
their niche, and the function warns. Use thinned records of the whole
range (e.g. GBIF, filtered with filter_occurrences() and
thin_by_cell()) and the same climate variables as for the regional
model, for the whole range; the layers may be coarser.
niche_truncation() then checks, for the chosen calibration area,
along which predictors and at which end the response is cut.
What to vary. The resolution of the niche space (n_bins) and the
records a niche cell needs (min_records): the printout gives the range
of unfilling over both, and a result that changes grade across them is
uncertain.
References
Goicolea, T., Adde, A., Broennimann, O., Garcia-Vinas, J.I., Gaston, A., Aroca-Fernandez, M.J., Guisan, A., Mateo, R.G. (2025) Spatially-nested hierarchical species distribution models to overcome niche truncation in national-scale studies. Ecography 2025, e07328. doi:10.1111/ecog.07328
Chevalier, M., Broennimann, O., Cornuault, J., Guisan, A. (2021) Data integration methods to account for spatial niche truncation effects in regional projections of species distribution. Ecological Applications 31, e02427.
Mateo, R.G., Gaston, A., Aroca-Fernandez, M.J., Broennimann, O., Guisan, A., Saura, S., Garcia-Vinas, J.I. (2019) Hierarchical species distribution models in support of vegetation conservation at the landscape scale. Journal of Vegetation Science 30, 386-396.
Pearson, R.G., Dawson, T.P., Liu, C. (2004) Modelling species distributions in Britain: a hierarchical integration of climate and land-cover data. Ecography 27, 285-298.
Examples
sim <- simulate_enm_data(seed = 1, n_presence = 200)
# the region of interest: the western third of the range
west <- terra::as.polygons(terra::ext(14, 17, 49, 55), crs = "EPSG:4326")
nc <- niche_coverage(sim$presence, sim$env, west, n_boot = 49,
n_null = 49)
nc
#> How much of the species' niche does the region contain?
#>
#> Records of the whole range: 200
#> of these inside the region: 33 (16%)
#>
#> Per variable:
#> variable coverage outside_records outside_region
#> env1 0.197 0.835 0.835
#> env2 0.791 0.175 0.000
#> coverage = part of the range of the whole-range records that the records
#> inside the region cover; outside_records = share of whole-range records
#> beyond the range of the records inside the region; outside_region = share
#> beyond the conditions of the region. Each variable is judged alone, so
#> these shares are smaller than those of the niche below, which counts
#> combinations of conditions.
#>
#> Unfilling when a cell needs more records to count as niche:
#> min_records niche_cells unfilling advice
#> 1 50 78% nested model strongly advised
#> 2 45 78% nested model strongly advised
#> 3 40 80% nested model strongly advised
#> 5 19 79% nested model strongly advised
#>
#> Unfilling with a coarser or finer grid (cells per axis):
#> n_bins niche_cells unfilling
#> 5 23 74%
#> 8 50 78%
#> 12 94 81%
#>
#> IN SHORT
#> - 78% (95% interval 77%-85%) of the species' niche has no record in the
#> region: 39 of the 50 cells of environmental space that the species
#> occupies (unfilling).
#> - A random sample of the whole-range records of the same size as the regional
#> records would leave 51% unfilled (SES = 9.1, p = 0.02). The gap comes
#> from the conditions of the region, not from its number of records.
#> - 74% of the niche lies in conditions that do not occur anywhere in the
#> region (not available).
#> - Counted by records instead, 78% of the whole-range records lie in the
#> unfilled part; this share cannot exceed the share of records outside the
#> region (84%). It understates the gap when most records come from the
#> region, so the advice uses the niche cells.
#> - Advice: nested model strongly advised. Very large gap: a regional model
#> sees less than half of the niche ("very poorly filled" in Goicolea et al.
#> 2025); its response curves are truncated and projections extrapolate. A
#> nested model is strongly advised.
#> - Depending on how many records a cell needs (1 to 5) and on the grid (5 to
#> 12 cells per axis), the unfilling is 74% to 81%: a very large gap in
#> every case.
#> - What a nested model adds: a model of the whole range knows conditions that
#> the regional records lack. When the region becomes warmer or drier, its
#> future conditions may lie outside the regional niche but inside the
#> conditions the species occupies elsewhere; a regional model then predicts
#> losses that the whole-range model does not. To see how much of the region
#> is in that situation, place its projected conditions with
#> classify_points(). This assumes that the regional populations can live in
#> the conditions of the populations elsewhere, or be replaced by them;
#> local adaptation would make the nested model too optimistic.
#> Niche: the cells of the space of the first two principal components of the
#> variables, cut into 8 x 8, that hold at least 1 whole-range record(s); each
#> counts once. Gaps: small below 10%, moderate to 25%, large to 50%, very
#> large above (rules of thumb; only the last is from Goicolea et al. 2025).
#> Records in unfilled cells: unfilled_records().
plot_niche_coverage(nc)
head(unfilled_records(nc))
#> id lon lat pc1 pc2 in_region niche_cell
#> 1 1 23.95485 50.93313 -1.1180377 -1.7573395 FALSE 17
#> 2 4 17.95243 51.18614 0.6922577 0.2603531 FALSE 45
#> 3 6 18.59947 53.87085 -0.9070477 1.4609097 FALSE 23
#> 4 7 18.24073 51.59984 0.4051108 0.3880005 FALSE 45
#> 5 8 18.85438 52.27038 -0.1572087 0.5515712 FALSE 30
#> 6 9 17.70016 49.37999 1.7052948 -0.5931845 FALSE 59
#> category
#> 1 elsewhere, absent
#> 2 elsewhere, absent
#> 3 elsewhere, absent
#> 4 elsewhere, absent
#> 5 elsewhere, absent
#> 6 elsewhere, absent
# plot_niche_coverage(nc, file = c("coverage.png", "coverage.pdf"))
