HABITUSReference Book

3. Data II: background, pseudo-absences, accessible area and thinning (① Data)

Tab: ① Data › Background & Pseudo-Absence Settings · Code: tabs/tab_data.py (UI), sdm_core.py DataFormatter.generate_pa_datasets, _sample_background (computation), sdm_sampling.py (strategies, bias surface), sdm_spatial.py (accessible area, thinning, variogram)

3.1 What this chapter covers

Most species records report presence only: we know where the species was seen, not where it is absent. For a model to discriminate presence it needs "comparison" points. HABITUS generates these points for three different purposes, as three separate sets:

Where these three sets are drawn from is set by the accessible area, with what weight by the sampling bias surface, and relative to which records by thinning. All of them are on the six sub-tabs of the Background & Pseudo-Absence Settings group at the upper right of ① Data, and they are applied together with the Load Data button (Section 2.8).

Processing order (sdm_core.py:2955-3207): record cleaning → thinning → accessible area mask (from the thinned records) → user's absence records → bias surface → strategy constraints (envelope, k-means) → pseudo-absence sets → MaxEnt background → ENFA background.

3.2 Screen layout

Sub-tab Tooltip text Which set In this book
ML Models ML Models (Pseudo-Absences) pseudo-absences §3.3
Own Absences My Own Absence Data true absences instead of / in addition to pseudo-absences §3.4
MaxEnt MaxEnt (Background Points) MaxEnt background §3.5
Sampling Bias Sampling Bias (Target Group) weights of all three sets §3.6
ENFA / Mahalanobis ENFA / Mahalanobis (Presence-Only) ENFA background §3.7
Study Area & Thinning Study Area & Thinning area of all three sets; presence records §3.8, §3.9

The sub-tab tooltips are defined in tabs/tab_data.py:214-219. The screenshots in this chapter show the settings of the example run (Abies nordmanniana).

3.3 Pseudo-absences: ML Models

Figure 3.1. ML Models sub-tab: PA repetitions 2, Pseudo-absences per repetition 1000, Sampling strategy random. The Min. distance from presences, Environmental envelope (env_const), Envelope tail trim and k-means classes fields are greyed out because the random strategy does not use them.
Figure 3.1. ML Models sub-tab: PA repetitions 2, Pseudo-absences per repetition 1000, Sampling strategy random. The Min. distance from presences, Environmental envelope (env_const), Envelope tail trim and k-means classes fields are greyed out because the random strategy does not use them.
Name in the UI What it does Default Range / options Code
PA repetitions: Number of independent pseudo-absence sets 2 1 – 10 tabs/tab_data.py:293-297
Pseudo-absences per repetition: Number of pseudo-absences in each set 1000 100 – 100,000 (step 500) tabs/tab_data.py:299-304
Sampling strategy: Which cells the pseudo-absences are drawn from random random, disk, sre, kmeans, env_const, geo_const, geo_env_const, geo_env_km_const tabs/tab_data.py:306-326, sdm_sampling.py:47-53
Min. distance from presences: Minimum distance to presences (km) 10 km 0 – 500 km tabs/tab_data.py:328-333
Environmental envelope (env_const): How the envelope is built pca pca, bioclim tabs/tab_data.py:335-342
Envelope tail trim: Proportion trimmed from each end of the envelope 0.05 0.00 – 0.45 tabs/tab_data.py:343-348
k-means classes: Number of clusters in environmental space 5 2 – 30 tabs/tab_data.py:349-353

Fields are enabled only for the strategy that uses them (tabs/tab_data.py:557-573): minimum distance for disk and geo_*; envelope and tail trim for env_const, geo_env_const, geo_env_km_const; k-means for kmeans, geo_env_km_const. If replace is selected in Own Absences, all fields are greyed out (§3.4).

3.3.1 PA repetitions

3.3.2 Pseudo-absences per repetition (number) and prevalence

3.3.3 Sampling strategy (eight strategies)

All strategies start from the same candidate set: cells that have a value in every continuous and categorical layer (_valid_cell_mask, sdm_core.py:2309-2330), restricted to those inside the accessible area if one is defined (sdm_core.py:2181-2203). The strategy-specific constraint is then applied (sdm_core.py:2205-2297), and the draw is made with bias and class weights, if any.

Strategy What it does Fields used R equivalent Code
random Equal-probability draw from candidate cells — biomod2 random, flexsdm random sdm_core.py:2291-2305
disk Excludes cells within Min. distance of each presence, draws randomly from the rest minimum distance biomod2 disk (minimum distance only) sdm_core.py:2243-2258
sre Draws from cells outside the bioclimatic envelope of the presences; the envelope is the 5%–95% range of each variable at the presences (fixed 0.05) biomod2 sre sdm_core.py:2079-2119, 3005-3022
kmeans k-means in scaled environmental space; draws from classes containing no presences, with equal total weight per class k sdm eRandom, flexsdm kmeans sdm_sampling.py:245-288
env_const Draws from cells outside the environmental envelope of the presences envelope, tail trim flexsdm env_const sdm_sampling.py:219-242
geo_const Same rule as disk minimum distance flexsdm geo_const sdm_sampling.py:26-27
geo_env_const Minimum distance and outside the envelope minimum distance, envelope, tail trim flexsdm geo_env_const sdm_core.py:2997-3003
geo_env_km_const Minimum distance, outside the envelope and presence-free k-means classes all flexsdm geo_env_km_const sdm_core.py:2399-2429

3.3.4 Min. distance from presences

3.3.5 Environmental envelope and Envelope tail trim

3.3.6 k-means classes

3.4 Your own absence records: Own Absences

Figure 3.2. Own Absences sub-tab: description text, empty Absence CSV field (Browse… and Clear) and the default mode "replace – use only my records as absences".
Figure 3.2. Own Absences sub-tab: description text, empty Absence CSV field (Browse… and Clear) and the default mode "replace – use only my records as absences".
Name in the UI What it does Default Range / options Code
Absence CSV: + Browse… / Clear Observed absence (or own background) records; once selected, the record count and the columns to be read are previewed empty CSV tabs/tab_data.py:478-491, 1162-1181
How to use them: Whether the records replace or supplement the pseudo-absences replace replace – use only my records as absences / augment – my records plus generated pseudo-absences tabs/tab_data.py:493-507

3.4.1 Absence CSV and columns

3.4.2 replace and augment modes

3.5 MaxEnt background: MaxEnt

Figure 3.3. MaxEnt sub-tab: Background points 10000, Sampling strategy random, Min. distance from presences 0.00 km; the boxes for weighting by the focal species' own record density (CIRCULAR / BIASED) and for saving the background to CSV are unchecked.
Figure 3.3. MaxEnt sub-tab: Background points 10000, Sampling strategy random, Min. distance from presences 0.00 km; the boxes for weighting by the focal species' own record density (CIRCULAR / BIASED) and for saving the background to CSV are unchecked.
Name in the UI What it does Default Range / options Code
Background points: Number of MaxEnt background points 10000 100 – 200,000 (step 1000) tabs/tab_data.py:789-794
Sampling strategy: Draw rule random random, disk tabs/tab_data.py:796-801
Min. distance from presences: Minimum distance to presences in disk 0 km 0 – 500 km tabs/tab_data.py:803-806
Weight background by the focal species' own presence density (CIRCULAR / BIASED - off by default) Weights the background by the record density of the focal species off on / off tabs/tab_data.py:808-822, sdm_core.py:3102-3142
Save background points to CSV (background_maxent.csv) Writes the background coordinates and predictor values off on / off tabs/tab_data.py:824-830, 1549-1563

3.5.1 Background points and strategy

3.5.2 Weighting by the focal species' own density (circular)

3.6 Sampling bias: Sampling Bias

Figure 3.4. Sampling Bias sub-tab: Target-group CSV and Bias raster fields empty, CSV lon / lat columns "auto", Kernel bandwidth "auto"; under Apply to, Pseudo-absences (ML models), MaxEnt background and ENFA / Mahalanobis background are checked.
Figure 3.4. Sampling Bias sub-tab: Target-group CSV and Bias raster fields empty, CSV lon / lat columns "auto", Kernel bandwidth "auto"; under Apply to, Pseudo-absences (ML models), MaxEnt background and ENFA / Mahalanobis background are checked.
Name in the UI What it does Default Range / options Code
Target-group CSV: Records of other species collected with the same method empty (off) CSV tabs/tab_data.py:402-405
CSV lon / lat columns: Coordinate columns in the target-group CSV auto column name tabs/tab_data.py:407-409, sdm_sampling.py:77-93
Bias raster: Sampling effort raster (large value = high effort) empty (off) .tif .tiff .img .asc tabs/tab_data.py:411-416, sdm_sampling.py:161-198
Kernel bandwidth: Gaussian smoothing (sigma) of the target-group density auto (0) 0 – 5000 km tabs/tab_data.py:418-423, sdm_sampling.py:103-158
Apply to: Sets the surface is applied to all three checked Pseudo-absences (ML models), MaxEnt background, ENFA / Mahalanobis background tabs/tab_data.py:425-441, sdm_core.py:2991-2993

3.6.1 Target-group surface and bias raster

3.6.2 Kernel bandwidth

3.6.3 Apply to

The surface is applied only to the checked sets (sdm_core.py:2991-2993). Checking all three ensures that all algorithms see the same bias correction and makes comparisons between algorithms consistent. Checking only one is useful for testing the effect of the correction in a single family of algorithms.

3.7 ENFA background: ENFA / Mahalanobis

Figure 3.5. ENFA / Mahalanobis sub-tab: Use dedicated background sample (recommended) checked, Background points 5000, Sampling strategy random, Min. distance from presences 0.00 km.
Figure 3.5. ENFA / Mahalanobis sub-tab: Use dedicated background sample (recommended) checked, Background points 5000, Sampling strategy random, Min. distance from presences 0.00 km.
Name in the UI What it does Default Range / options Code
Use dedicated background sample (recommended) Draws a separate background for ENFA on on / off tabs/tab_data.py:858-864
Background points: Number of background points 5000 100 – 100,000 (step 1000) tabs/tab_data.py:866-872
Sampling strategy: Draw rule random random, disk tabs/tab_data.py:874-879
Min. distance from presences: Minimum distance in disk 0 km 0 – 500 km tabs/tab_data.py:881-885

3.8 Accessible area: Study Area & Thinning (upper half)

Figure 3.6. Study Area & Thinning sub-tab with the settings of the example run: Accessible area "buffer – discs around each occurrence record", Buffer radius 200.00 km; below, Keep one record per raster cell checked, Thinning distance "Typed or automatic", Choose the distance automatically from the variogram range checked (hence Minimum distance between records greyed out).
Figure 3.6. Study Area & Thinning sub-tab with the settings of the example run: Accessible area "buffer – discs around each occurrence record", Buffer radius 200.00 km; below, Keep one record per raster cell checked, Thinning distance "Typed or automatic", Choose the distance automatically from the variogram range checked (hence Minimum distance between records greyed out).
Name in the UI What it does Default Range / options Code
Accessible area: Method for building the background/pseudo-absence area buffer buffer – discs around each occurrence record, mcp_buffer – buffered minimum convex polygon, polygon – my own calibration area layer, none – sample the whole raster extent tabs/tab_data.py:644-666
Buffer radius: Buffer radius; in polygon, the buffer added around the polygons 200 km 0 – 5000 km (step 50) tabs/tab_data.py:668-674, 609-618
Calibration layer: + Browse… Calibration polygon layer (visible only in polygon) empty .shp .gpkg .geojson .json .kml .gml tabs/tab_data.py:677-691
Keep only the polygons containing an occurrence record Keeps only polygons that contain records (only in polygon) on on / off tabs/tab_data.py:693-701

3.8.1 Why an accessible area

A species does not occur in places it has never been able to reach, even if they are suitable. These cells are not evidence of "unsuitable"; but when they enter the model as background or pseudo-absences, the model learns them as such (Barve et al. 2011). The accessible area (M in the BAM framework) restricts the area from which the background is drawn to the region the species can reach. Keeping the extent wide adds cells with conditions very different from the presences to the background; discrimination becomes easier and AUC rises artificially (Lobo et al. 2008; VanDerWal et al. 2009). The mask is applied to all three sets (pseudo-absences, MaxEnt, ENFA); it is not applied to the user's absence records. The map is still produced for the whole extent (or the study boundary).

3.8.2 Accessible area methods

3.8.3 Buffer radius

3.8.4 Calibration layer and "containing a record"

3.8.5 accessible_area.tif

If an accessible area is defined, the mask is written to the species' output folder as accessible_area.tif (1 = inside, 0 = outside, compressed uint8; tabs/tab_data.py:1536-1548, sdm_spatial.py:1065-1075). ⑥ Range Change uses this file to report change within this area separately (Chapter 9). If none is selected, the file is not written.

3.9 Thinning the records: Study Area & Thinning (lower half)

Name in the UI What it does Default Range / options Code
Keep one record per raster cell (recommended) One record in each predictor cell on on / off tabs/tab_data.py:722-731 (Section 2.8.3)
Thinning distance: Source of the thinning distance Typed or automatic Typed or automatic, One cell, 10 km (Boria 2014) tabs/tab_data.py:733-743
Choose the distance automatically from the variogram range Chooses the distance from the variogram range (only in Typed or automatic) off on / off tabs/tab_data.py:745-751
Minimum distance between records: Manually entered distance (only in Typed or automatic with automatic off) 0 km (no thinning) 0 – 500 km tabs/tab_data.py:753-765

3.9.1 How thinning works

3.9.2 Presets: One cell and 10 km

3.9.3 Automatic distance: half the variogram range and the reduction rule

3.10 Outputs and what passes to the next step

3.11 Expert questions

Q1. Is the random pseudo-absence draw in HABITUS the same as random in biomod2? Answer: The rule is the same: an equal-probability draw without replacement from valid cells (sdm_core.py:2301-2302). There are two differences. First, HABITUS by default restricts the draw to a 200 km accessible area; biomod2 has no such default and uses the whole extent. Second, pseudo-absences are drawn from cell centres, and within a set a cell is selected only once. Presence cells are not excluded in random; a pseudo-absence may fall in a presence cell.

Q2. Why do strategies that move pseudo-absences away from presences inflate the scores? Answer: AUC and TSS measure the model's ability to discriminate presence from absence. When pseudo-absences are moved geographically (disk) or environmentally (sre, env_const) away from presences, discrimination becomes easier by construction of the data; the measured skill comes more from the sampling design than from the model (VanDerWal et al. 2009; Barbet-Massin et al. 2012). When comparing strategies on the same data, it is not the scores but the performance obtained with independent validation data (⑦ Validation) that should be compared.

Q3. Why is the accessible area buffer 200 km, and where does this value come from? Answer: 200 km is a starting value (tabs/tab_data.py:669, sdm_core.py:1400); in the code it has no species-specific justification. The UI tooltip asks for the radius to be chosen from the species' dispersal ability and the age of the range. Barve et al. (2011) stress that M must be defined specifically for the species and the question; Rojas-Soto et al. (2024) recommend a calibration area based on biogeographic units (polygon in HABITUS). The value is written to the record in every run and should be reported.

Q4. Is the buffer distance computed geodesically? Answer: No, it is computed approximately. buffer and mcp_buffer use an anisotropic Euclidean distance transform that treats cell height as constant and cell width as reduced by the cosine of the records' mean latitude (sdm_spatial.py:1022-1062). In areas with a small latitudinal span the error is small; for a range extending thousands of km north–south, the east–west width of the buffer deviates at the extremes. Thinning and minimum distance, by contrast, are computed with haversine.

Q5. Do the user's absence records also enter MaxEnt? Answer: No. Own Absences records enter only the absence side of pa_datasets (sdm_core.py:3035-3082). MaxEnt uses its own background (sdm_core.py:4595-4598); the background is not treated as absence. ENFA also uses its own background. There is no path in the code for a user who wants to give true absences to MaxEnt as "background".

Q6. How is the bandwidth of the target-group surface chosen; what is its R equivalent? Answer: With auto, 1.06\,\min(s,\ \mathrm{IQR}/1.34)\,n^{-1/5} is used for each axis; this is one quarter of the MASS bandwidth.nrd value and identical to the sigma that kde2d uses internally (sdm_sampling.py:143-151). The density is obtained by smoothing the cell counts with a Gaussian filter; mass beyond the boundary is lost (mode="constant"). The surface is scaled to its maximum value and floored at 10^{-6}, so that cells with no target records can still be selected, albeit with very low probability. Kramer-Schadt et al. (2013) and Phillips et al. (2009) give the rationale for this approach.

Q7. Why is the automatic thinning distance half the variogram range, and why is it reduced? Answer: The range is the distance at which autocorrelation in the predictors vanishes; half of it is a common starting point for reducing repeated environmental information between records, and because the same range determines the block size, the two decisions are consistent (sdm_core.py:2433-2442). In climate layers with a strong regional trend the range comes out at hundreds of km and its half drops most of the records; since the aim of thinning is to remove redundancy, not the data set, the distance is halved until at least 50% of the records remain (sdm_core.py:2571-2594). In the example run it was reduced from 75.7 km to 4.7 km.

Q8. Does HABITUS's thinning give the same result as spThin? Answer: The rule is the same (minimum distance between any two retained records, great-circle distance); the algorithm differs. spThin thin() performs many random repetitions and selects the set retaining the most records (Aiello-Lammens et al. 2015); HABITUS performs a greedy selection with 3 repetitions (sdm_spatial.py:888-937), and a single repetition in the automatic distance search. The number of retained records may be slightly lower than spThin's best; exact equality has not been tested.

Q9. What is the difference between sre and env_const (bioclim)? Answer: Both use the same computation (_compute_sre_mask): the [q,\,1-q] range of the presences in each variable; a cell within range in all variables is inside the envelope (sdm_core.py:2079-2119). In sre, q is fixed at 0.05 (sdm_core.py:3010-3011); in env_const + bioclim it is set with Envelope tail trim. Variables with values at fewer than 4 presences are not included in the envelope. env_const + pca, by contrast, works on two principal components and prevents the envelope from becoming meaningless as the number of variables grows.

Q10. Do the background and pseudo-absences all come from the same seed; are the repetitions independent of each other? Answer: DataFormatter sets up a single seeded generator and all draws are made from it in sequence (sdm_core.py:1505). Because each pseudo-absence set is drawn from the next state of the generator, the sets differ from each other and are reproduced with the same seed in the same order. Changing the number of repetitions also changes the subsequent MaxEnt and ENFA backgrounds, because the generator state has advanced.

Q11. What happens if the accessible area is small and has fewer cells than the requested number of background points? Answer: All valid cells in the area are used, fewer points than requested are drawn and a warning is written (sdm_core.py:2190-2203); how many cells were found for which request is added to the run record (cells_short_of_request). The background is then a complete census of the area (Phillips and Dudík 2008). The draw is not extended to the whole extent; this preserves the M defined by the user.

Q12. Which settings on this tab affect the result most? Answer: No systematic sensitivity analysis has been carried out with the example data. From the structure of the code and the literature, the following order is expected: (1) accessible area method and radius (determines the environmental coverage of the background; Barve et al. 2011), (2) pseudo-absence strategy (determines the difficulty of discrimination; Barbet-Massin et al. 2012), (3) bias correction (determines whether the map follows bias or environment; Phillips et al. 2009), (4) thinning and the one-per-cell rule (determine the number of records used; from 626 to 143 in the example run). Pseudo-absence and background counts, within a reasonable range, are less influential.

3.12 Common mistakes and pitfalls

3.13 References

Aiello-Lammens, M.E., Boria, R.A., Radosavljevic, A., Vilela, B., Anderson, R.P., 2015. spThin: an R package for spatial thinning of species occurrence records for use in ecological niche models. Ecography 38, 541–545. https://doi.org/10.1111/ecog.01132

Barbet-Massin, M., Jiguet, F., Albert, C.H., Thuiller, W., 2012. Selecting pseudo-absences for species distribution models: how, where and how many? Methods in Ecology and Evolution 3, 327–338. https://doi.org/10.1111/j.2041-210X.2011.00172.x

Barve, N., Barve, V., Jiménez-Valverde, A., Lira-Noriega, A., Maher, S.P., Peterson, A.T., Soberón, J., Villalobos, F., 2011. The crucial role of the accessible area in ecological niche modeling and species distribution modeling. Ecological Modelling 222, 1810–1819. https://doi.org/10.1016/j.ecolmodel.2011.02.011

Boria, R.A., Olson, L.E., Goodman, S.M., Anderson, R.P., 2014. Spatial filtering to reduce sampling bias can improve the performance of ecological niche models. Ecological Modelling 275, 73–77. https://doi.org/10.1016/j.ecolmodel.2013.12.012

Kramer-Schadt, S., Niedballa, J., Pilgrim, J.D., Schröder, B., Lindenborn, J., Reinfelder, V., Stillfried, M., Heckmann, I., Scharf, A.K., Augeri, D.M., Cheyne, S.M., Hearn, A.J., Ross, J., Macdonald, D.W., Mathai, J., Eaton, J., Marshall, A.J., Semiadi, G., Rustam, R., Bernard, H., Alfred, R., Samejima, H., Duckworth, J.W., Breitenmoser-Wuersten, C., Belant, J.L., Hofer, H., Wilting, A., 2013. The importance of correcting for sampling bias in MaxEnt species distribution models. Diversity and Distributions 19, 1366–1379. https://doi.org/10.1111/ddi.12096

Lobo, J.M., Jiménez-Valverde, A., Real, R., 2008. AUC: a misleading measure of the performance of predictive distribution models. Global Ecology and Biogeography 17, 145–151. https://doi.org/10.1111/j.1466-8238.2007.00358.x

Phillips, S.J., Anderson, R.P., Schapire, R.E., 2006. Maximum entropy modeling of species geographic distributions. Ecological Modelling 190, 231–259. https://doi.org/10.1016/j.ecolmodel.2005.03.026

Phillips, S.J., Dudík, M., 2008. Modeling of species distributions with Maxent: new extensions and a comprehensive evaluation. Ecography 31, 161–175. https://doi.org/10.1111/j.0906-7590.2008.5203.x

Phillips, S.J., Dudík, M., Elith, J., Graham, C.H., Lehmann, A., Leathwick, J., Ferrier, S., 2009. Sample selection bias and presence-only distribution models: implications for background and pseudo-absence data. Ecological Applications 19, 181–197. https://doi.org/10.1890/07-2153.1

Roberts, D.R., Bahn, V., Ciuti, S., Boyce, M.S., Elith, J., Guillera-Arroita, G., Hauenstein, S., Lahoz-Monfort, J.J., Schröder, B., Thuiller, W., Warton, D.I., Wintle, B.A., Hartig, F., Dormann, C.F., 2017. Cross-validation strategies for data with temporal, spatial, hierarchical, or phylogenetic structure. Ecography 40, 913–929. https://doi.org/10.1111/ecog.02881

Rojas-Soto, O., Forero-Rodríguez, J.S., Galindo-Cruz, A., Mota-Vargas, C., Parra-Henao, K.D., Peña-Peniche, A., Piña-Torres, J., Rojas-Herrera, K., Sánchez-Rodríguez, J.D., Toro-Cardona, F.A., Trinidad-Domínguez, C.D., 2024. Calibration areas in ecological niche and species distribution modelling: Unravelling approaches and concepts. Journal of Biogeography 51, 1416–1428. https://doi.org/10.1111/jbi.14834

Valavi, R., Elith, J., Lahoz-Monfort, J.J., Guillera-Arroita, G., 2019. blockCV: An R package for generating spatially or environmentally separated folds for k-fold cross-validation of species distribution models. Methods in Ecology and Evolution 10, 225–232. https://doi.org/10.1111/2041-210X.13107

VanDerWal, J., Shoo, L.P., Graham, C., Williams, S.E., 2009. Selecting pseudo-absence data for presence-only distribution modeling: How far should you stray from what you know? Ecological Modelling 220, 589–594. https://doi.org/10.1016/j.ecolmodel.2008.11.010