Heterra

Part 5 · Model evaluation · Chapter 8

DSI

Degree of spatial interpretability

The question

How much of the spatial structure of my variable has each model absorbed, and how much is still left in its residuals?

You need

One point table with longitude and latitude, the observed y, and one field of out-of-sample residuals (or predictions) per model. At least 30 complete rows.

You get

For every model, the share of spatial autocorrelation and of spatial heterogeneity it explains (η), the DSI range θ₁ to θ₃, and R², RMSE and MAE next to them. Since version 1.6.0 also maps of a local DSI.

1The method

The idea

R², RMSE and MAE say how close a model's predictions are to the observed values. They do not say whether the model has captured the spatial structure of the variable. A model can be accurate on average and still leave residuals that are clustered on the map, or that differ from one kind of place to another. DSI looks at exactly that: it measures a spatial characteristic in the observed y, measures it again in the model's residuals, and reports the share that is gone.

Two characteristics are measured, each with an indicator δ:

CharacteristicIndicator δHow it is computed
Spatial autocorrelation (a)Moran's IWith row-standardised weights of the k nearest neighbours of each point
Spatial heterogeneity (h)The q statistic of the geographical detectorOver strata that are the leaves of a regression tree of y on the predictors

η = (δ₀ − δr) / δ₀
δ₀ is the indicator of the observed y and δr the indicator of the model's residuals. η is computed for autocorrelation (ηa) and for heterogeneity (ηh).
θ₁ = min(ηa, ηh), θ₂ = max(ηa, ηh), θ₃ = 1 − (1 − ηa)(1 − ηh)

η near 1 means that the residuals keep almost none of that structure. η near 0 means that the model absorbed none of it. A negative η means that the residuals carry more of the structure than the data did. The three θ values combine the two η into a range: θ₁ is the lower end, θ₃ the upper end, and θ₂ lies between them. In the tables they are the columns theta_min, theta_probable and theta_max.

Flow chart of DSI: spatial data and a model, then step 1, eta from the indicator of the dependent variable and of the residuals, and step 2, the theta range
How the method works. A spatial characteristic is measured on the dependent variable (δ₀) and on the residuals of the model (δr). Step 1 turns each pair into η, here for autocorrelation and for heterogeneity. Step 2 combines the η values into the range from θmin to θmax, which this chapter writes θ₁ to θ₃. Source: Liu et al. (2026), Fig. 1.

When to use it

Where it has been used

FieldResponse ySpatial unitStudy
Plant diversitySpecies richness0.5° grid cellLiu et al. (2026)
Forest biomassAbove-ground biomass of treesSample plotLiu, Song, Yi & Zhang (2026), with DG, the local form of DSI, which is outside Heterra

Any set of points with coordinates, one numeric response and the held-out residuals of one or more models fits.

Triangles of the theta range of five models
A published result. The θ range of five models. Each triangle runs from θ1 to θ3, with its top at θ2; the model with the highest range is in the first row. Drawn with R from the demonstration data of the author's tutorial, in the form of Liu et al. (2026), Fig. 6.

Keep in mindDSI describes the residuals you give it. It does not fit, tune or validate a model, and a high θ does not make a model accurate: accuracy and spatial interpretability can rank models differently, so report both.

2In Heterra

2.1 Prepare your data

Heterra does not fit the models. You build them in your own software and bring one table of results. To make that table:

  1. Hold out data the model does not see: a test set, or the folds of a cross-validation.
  2. Fit each model on the rest and predict the held-out points.
  3. For every held-out point write one row: its longitude and latitude, the observed y, and for each model the residual (observed − predicted). You can store the predictions instead; Heterra then computes y − prediction.
  4. Add the predictors if you want the strata of q to come from a regression tree, as in the paper.

Save the table as CSV, shapefile, GeoPackage or GeoJSON (Part 1 shows how to add data). Since version 1.6.0 the layer may also be polygons or a regular grid; the location of each row is still the pair of coordinate fields you choose (for a layer with geometry, Geometry X and Geometry Y are offered too).

FieldTypeIn the example
Longitude, latitudeNumbers, WGS84 degreeslon, lat
Dependent variable (observed y)Numbery
Model fields, one per modelNumbers: residuals or predictionserror_rpart, error_rf, error_xgbTree, error_cubist, error_knn
Predictors (optional)Numberstemperature, precipitation, elevation, soil_ph, distance_km, noise_var
Boundary (optional)A polygon layerdsi_boundary: the outline drawn on the map and on the maps of the local DSI. It changes no result.

A prefix error_ or residual_ (for predictions pred_, prediction_ or predicted_) is dropped from the model name, so error_rf appears as rf. The sign of the residuals does not affect DSI. The example has 310 simulated test points in an irregular study area across Australia, so its numbers illustrate the tool and do not describe a real study.

2.2 Run the example, step by step

Open the tool from the Toolbox (Model evaluation → DSI), click Tutorial, then Load Example. The test points and the study-area boundary appear on the map, and the panel on the right is filled in for you.

Heterra after Load Example: the 310 test points inside the study-area boundary and the DSI panel at step 1
After Load Example: the layers on the left, the test points on the map, the DSI panel on the right at step 1 of 4.

The panel has four steps. Next moves on; Run appears at the last step, because only that step computes.

  1. DSI panel, step 1 DataDataChoose the layer, Longitude lon, Latitude lat and the Dependent variable (observed y) y. The Study-area boundary (for the maps) is optional.
  2. DSI panel, step 2 ModelsModelsKeep Residuals (observed − predicted) and tick the five error_ fields under Model residual fields.
  3. DSI panel, step 3 StrataStrataTick the six predictors. They give the strata of q: the leaves of a regression tree of y on them.
  4. DSI panel, step 4 NeighboursNeighboursKeep k = 8 and Projected EPSG:3577, the paper's Australian setting, and 50 for Local window: nearest points. Click Run.

The run takes well under a second. The Chart page opens with the θ range figure, and the panel lists every result under Outputs: the tables, the strata field, the figures, and since version 1.6.0 the local DSI fields and their two figures of maps. A green line says that the results match the reference results computed with R.

Heterra after the DSI run: the theta range figure on the Chart page and the results in the panel
After Run: the θ range figure. The menu above the figure and the Outputs list in the panel open the other figures and the tables.

2.3 With your own data

  1. Add your table (Add Data), open DSI from the Toolbox and choose the layer, the coordinates and y in step 1.
  2. In step 2 say whether the model fields hold residuals or predictions, and tick one field per model.
  3. In step 3 tick the predictors the models used. In step 4 choose Great-circle, WGS-84 (any region) unless your study area is in Australia.

3Reading the results

Read the results in this order: the δ and η table first (what structure is in the data, and what is left in the residuals?), then the θ range (how do the models compare?), then DSI against accuracy (do the two rankings agree?), then the strata and the diagnostics (can the numbers be trusted?), and last the local maps (where on the map?).

3.1 Autocorrelation and heterogeneity explained (δ, η)

The table Spatial autocorrelation and heterogeneity explained (δ, η) has one row per model. In the example the observed y has Moran's I δ₀a = 0.652 and q δ₀h = 0.453; these two values are the same in every row.

ModelMoran's I of residualsηaq of residualsηh
xgbTree0.4310.3390.1810.601
rpart0.5240.1960.2620.423
knn0.5440.1650.2570.433
rf0.5680.1290.2520.445
cubist0.5880.0980.2640.416

What it shows. For each characteristic, the indicator of the data, the indicator of the residuals and the share η that the model explains. The table DSI results (Table 3) holds the same values with the p values of Moran's I and θ₁ to θ₃ added, in the layout of the paper's Table 3.

How to read it. Compare each residual value with the value of the data. The residuals of xgbTree have a Moran's I of 0.431 against 0.652 in y, so the model explains 34% of the autocorrelation (ηa = 0.339); the residuals of cubist still have 0.588, so it explains 10%. Then compare the two η columns: here every model removes more heterogeneity than autocorrelation.

In a paper

"The response is spatially autocorrelated (Moran's I = 0.65, k = 8 nearest neighbours) and heterogeneous (q = 0.45 over regression-tree strata). The residuals of xgbTree retain a Moran's I of 0.43 and a q of 0.18: the model explains 34% of the spatial autocorrelation and 60% of the spatial heterogeneity (Liu et al. 2026)."

3.2 θ range by model

Theta range by model: one triangle per model from theta 1 to theta 3 with the apex at theta 2, xgbTree at the top
θ range by model: one triangle per model. The base runs from θ₁ to θ₃, the dashed apex is at θ₂. Models are ordered by θ₃.
Modelθ₁θ₂θ₃
xgbTree0.3390.6010.736
rpart0.1960.4230.536
knn0.1650.4330.527
rf0.1290.4450.516
cubist0.0980.4160.474

What it shows. The DSI of each model as a range. θ₁ is the smaller of the two η and θ₂ the larger; θ₃ combines both.

How to read it. A triangle further to the right is a model whose residuals keep less spatial structure. xgbTree absorbs the most (θ₃ = 0.736) and its whole triangle lies to the right of the others. The other four models overlap: their θ₃ values lie between 0.474 and 0.536, and their order by θ₂ is not the order by θ₃. A wide triangle means that the model treats the two characteristics very differently, so look at ηa and ηh in the table before you summarise the model with one number.

In a paper

"The degree of spatial interpretability is highest for xgbTree (θ₁ = 0.34, θ₂ = 0.60, θ₃ = 0.74). The other four models are close to each other (θ₃ from 0.47 to 0.54), and all five explain more spatial heterogeneity than spatial autocorrelation."

3.3 DSI and accuracy metrics

Three panels: DSI against R squared, RMSE and MAE, one point per model with a bar from theta 1 to theta 3
DSI and accuracy metrics: a, R²; b, RMSE; c, MAE. Each point is a model at θ₂; the bar runs from θ₁ to θ₃.
ModelR²RMSEMAEθ₃
xgbTree0.2744.0193.2360.736
rpart0.1474.3583.5240.536
knn0.3033.9393.1910.527
rf0.3653.7593.0290.516
cubist0.2913.9713.1990.474

What it shows. The accuracy of each model, computed from the same residuals, against its DSI. R² is 1 − SSE/SST, not the squared correlation.

How to read it. If accuracy and spatial interpretability agreed, the points would rise from left to right in panel a and fall in panels b and c. Here they do not: rf has the best R², RMSE and MAE but only the fourth-highest θ₃, and xgbTree has the highest θ₃ with the fourth-highest R². Accuracy and spatial interpretability rank models differently, so a model chosen on accuracy alone can leave more spatial structure in its residuals than a less accurate one.

In a paper

"Accuracy and spatial interpretability rank the models differently. Random forest is the most accurate model (R² = 0.36, RMSE = 3.76, MAE = 3.03) but has only the fourth-highest DSI (θ₃ = 0.52), whereas xgbTree has a lower R² (0.27) and the highest DSI (θ₃ = 0.74)."

3.4 Strata and diagnostics

Map of the test points coloured by the field dsi_stratum, with a legend of eight strata
The Map page after the run: each test point in the colour of its stratum, with the legend of dsi_stratum.

What it shows. The run adds a copy of the layer with the field dsi_stratum: the stratum of each row that q was computed on. The map colours the points by stratum. The example has 8 strata, the leaves of the regression tree; the labels in the legend are the tree's leaf numbers, not ranks.

How to read it. q depends on the strata, so check that they are sensible: several strata, none with only a handful of points. An RColorBrewer palette has at most 12 colours, so with more strata the colours repeat in order, and the legend says so. The table Diagnostics flags a response without significant autocorrelation (ηa then has little meaning), negative η and wide θ ranges. Settings used records the number of rows, k, the distance and the kind of strata.

3.5 Local DSI (new in version 1.6.0)

The tables give one value per model for the whole study area. The local view repeats the computation around every location. The window of a location is its 50 nearest points, itself among them. Inside the window Moran's I and q are computed again, for y and for the residuals of each model, and give a local ηa and a local ηh by the same formula, (δ₀ − δr) / δ₀. The local DSI is the larger of the two, as θ₂ is.

A share is given only where the window has a pattern to explain. The local ηa needs a Moran's I of y in the window that is positive and significant (one-sided p < 0.05); the local ηh needs a q of y in the window above 0.05. Elsewhere the value is missing, and the point is grey on the maps. In the example 110 of the 1550 local values (310 locations × 5 models) are missing; the local ηa exists at 223 locations, the local ηh at 280, and the local DSI at 288.

Five maps of the study area, one per model, the test points coloured by local DSI from 0 (blue) to 1 (red), grey where there is no value
Maps of the local DSI: one map per model on one colour scale from 0 (blue) to 1 (red). Grey: nothing to explain in that window.
ModelMedian local DSIMedian local ηaMedian local ηhGlobal θ₂
xgbTree0.7310.7230.6780.601
knn0.5510.3980.5100.433
rf0.5150.3520.5040.445
cubist0.4910.2970.4420.416
rpart0.4590.4230.3960.423

What it shows. Where each model explains the spatial structure of y and where it does not. The run adds a copy of the layer with the fields dsi_local_<model>, eta_a_local_<model>, eta_h_local_<model> and dsi_window_n, the number of points in the window, so you can also style them on the Map page. The medians in the table above were computed from these fields.

How to read it. Compare the same place across the five maps. xgbTree is orange to red over most of the area, which agrees with its global θ. In the south-east of the centre several models are blue: there the residuals keep nearly all of the local structure of y. Neighbouring windows share most of their points, so the maps are smooth by construction, and the local values do not average to the global ones: a window can have a pattern that the whole area does not, and the reverse. A local value is a ratio of two numbers from 50 points and can leave the range 0 to 1 (in the example from −1.30 to 1.66); the colour scale stops at 0 and 1.

Five maps, one per model, the points in nine colours for three classes of the local autocorrelation explained crossed with three classes of the local heterogeneity explained, and a key of three by three colour squares
Maps of the two local explained shares: one map per model and the key. Blue grows with the autocorrelation explained, red with the heterogeneity explained; dark means both are high.

What it shows. The two local shares together. Each is cut into three classes at its terciles over all models (here 0.291 and 0.542 for the autocorrelation explained, 0.414 and 0.593 for the heterogeneity explained; the key's axes give these limits), and the nine combinations get nine colours.

How to read it. Dark points are places where a model explains both characteristics well; pale points are places where it explains neither. Blue points explain autocorrelation but little heterogeneity, red points the reverse. xgbTree is dark over most of the area. For the other models the west is mostly pale to blue and parts of the east are red: the same model explains a different characteristic in different parts of the area. Because the classes are shared by all models, colours can be compared between maps.

How far to trust itThe local DSI is an addition of Heterra 1.6.0. It is not defined in Liu et al. (2026, IJGIS), there is no R reference for it, and its numbers are therefore not checked against R as the tables are. Use it to explore where the models differ, and report the window (50 nearest points, or your distance) with every local number. Several hundred windows tested at 0.05 give some false positives.

In a paper

"A local DSI was computed in windows of the 50 nearest test points (Heterra 1.6.0), where the window showed significant positive autocorrelation of y (p < 0.05) or a q of y above 0.05. Its median is highest for xgbTree (0.73) and lies between 0.46 and 0.55 for the other models; all models have low values in the south-east of the centre of the study area (Figure X)."

Export a figure from the Chart page as PDF or SVG (vector) or PNG at 300 dpi; Data CSV saves the numbers behind it. Export results in the panel writes a report of the run with the method, the steps, the figures and the tables (Part 1). The report does not yet include the local values.

3.6 Reading the results together

The outputs tell one story in three parts: what structure the data have (δ₀), how much of it each model explains (η and θ), and whether the most accurate model is also the one that explains the most structure. The last part is the main finding of a DSI analysis. Read them in this order:

  1. Autocorrelation and heterogeneity explained (δ, η): the structure in y first, then what is left in the residuals of each model.
  2. θ range by model: the ranking of the models, and how wide each range is.
  3. DSI and accuracy metrics: the models on which the two rankings disagree.
  4. Strata and diagnostics: what you must state as a limit before you write: a response without significant autocorrelation, a negative η, a wide θ range, strata with few points.
  5. Local DSI: where on the map the models explain the structure, as an exploration after the global results.

What DSI is notIt does not replace accuracy. The two often agree in part, and DSI finds the models on which they disagree. Choose a model by reading both. The DSI of the tables is one value for the whole study area; the local maps of section 3.5 show where a model explains the structure, with the limits named there.

3.7 From the results to a manuscript

SectionWhat to writeFrom Heterra
MethodsThe two spatial characteristics and their indicators; η and the θ range; the list of models and how the residuals were held out; k, the distance and how the strata were madeTable Settings used; the settings of the run (in the exported report)
ResultsFollow the order accuracy, DSI, disagreement. Give δ₀ before any η. Every finding has a number. State the limits that the diagnostics flagTables Spatial autocorrelation and heterogeneity explained (δ, η) and DSI results (Table 3); figures θ range by model and DSI and accuracy metrics; table Diagnostics
DiscussionWhy accuracy and spatial interpretability disagree: a model can lower its errors by smoothing towards the local mean, and still leave the spatial arrangement of the errors as it was. Whether the ranking holds with another k and other strataFigure DSI and accuracy metrics; a second run with another k or with k-means strata (both runs stay in History)
Common pitfalls
  • Use held-out residuals. The training residuals of an overfitted model give a false η near 1.
  • The strata of q come from the predictors, never from y. Strata cut from y push its own q towards 1, and η then has no meaning.
  • The strata are not neutral: tree strata and k-means strata can rank the models differently on heterogeneity. Name the rule in the Methods, and report both rankings if they differ.
  • Distances must be right for your region. Outside Australia choose great-circle distances, or the nearest neighbours and Moran's I are wrong.

4Exercises

Exercises 1 to 3 use the example. Exercise 4 is for your own data.

Exercise 1Read

Run the example with its settings. Which model has the largest θ₃, and what are its η for autocorrelation and for heterogeneity? Which model has the smallest θ₁?

Answer

xgbTree: θ₃ = 0.736, with ηa = 0.339 and ηh = 0.601. cubist has the smallest θ₁ (0.098), which is its η for autocorrelation.

Exercise 2Explore

Open the table Spatial autocorrelation and heterogeneity explained (δ, η) from the Outputs list. Whose residuals keep the most spatial autocorrelation, and how does their Moran's I compare with that of y? Then open the Map page: how many strata was q computed on?

Answer

cubist: its residuals have a Moran's I of 0.588 against 0.652 for y, so almost all of the autocorrelation is still there (ηa = 0.098). The legend of dsi_stratum lists 8 strata.

Exercise 3Interpret

A colleague writes: "Random forest has the highest R², so it also explains the spatial structure of y best." Check this against the two figures and the tables. Is the sentence justified?

Answer

No. rf has the best R² (0.365), RMSE and MAE, but its θ₃ (0.516) is only the fourth-highest of five. Its residuals keep a Moran's I of 0.568 of the 0.652 in y (ηa = 0.129). xgbTree, with a lower R² (0.274), has θ₃ = 0.736. Accuracy and spatial interpretability are different properties and have to be reported separately.

Exercise 4Your data

Fit at least two models to your own data in the software you normally use, with a test set or cross-validation. Build the table of section 2.1 and run DSI. Write three sentences for a results section: one on the structure in the data (δ₀ of Moran's I and of q), one on what each model explains (η and θ₁ to θ₃), and one comparing the DSI ranking with the accuracy ranking. Export the comparison figure as PDF.

Checklist

Do the residuals come from points the models did not see? Are the coordinates WGS84 degrees, and did you choose great-circle distances outside Australia? Did you look at the map of dsi_stratum and at the Diagnostics table? Did you report k, the distance and how the strata were made? Does each sentence give a number?

References

Heterra guide, for version 1.6.0. © 2026 Yongze Song. Documentation and tutorial data: CC BY 4.0.