Reading route. Follow the polygon-to-graph example, the three main neighbour rules, row standardisation and the worked spatial lag. Check the graph diagnostics before applying a rule. Higher-order neighbourhoods and inverse-distance decay are optional extensions; the Singapore maps illustrate how membership changes.
Neighbours are part of the question¶
The income maps in Section 6.1 invite us to compare nearby areas. But a shared border, a short straight-line distance and a short journey describe different relationships. A weights specification makes that choice explicit before we calculate spatial association.
After reading, you should be able to translate a neighbour rule into a matrix, distinguish contiguity, distance-band and k-nearest-neighbour weights, calculate a spatial lag, and explain row standardisation and graph diagnostics. We use nonnegative weights and exclude self-neighbours unless a later statistic explicitly states otherwise.
From polygons to a neighbour graph¶
Rook contiguity connects polygons sharing a boundary segment of positive length. Queen contiguity also permits contact at a point. On a regular square grid these resemble chess moves: an interior cell has four first-order rook neighbours or eight first-order queen neighbours. Queen includes rook contacts; it does not require every neighbour to share both an edge and a corner.

Figure 1:The chess analogy on a regular grid. Rook selects shared edges; the diagonal-only bishop illustration selects corner contacts; queen includes both. The focal cell is excluded from its own neighbourhood.

Figure 2:Chong Boon, Singapore: the same focal subzone has additional neighbours under queen contiguity because point contacts are included. The highlighted areas show neighbour membership, not income values or statistical significance.
Figure 3:Six synthetic units. Rook neighbours share an edge of non-zero length; point contact alone is insufficient. These are teaching geometries, not Malaysian administrative boundaries.
Figure 4:The same units as a graph. Links are 1–2, 1–4, 1–5, 2–4, 2–5, 3–5, 3–6 and 4–5. The graph preserves the selected relationships, not polygon shape or area.
Let when is a selected neighbour of , and zero otherwise. With row and column order 1–6,
The diagonal is zero. The matrix is symmetric because shared-edge contact is mutual. Unit 5 has four neighbours; unit 6 has only one. There are eight undirected links but sixteen nonzero matrix entries: each link appears in both directions. Preserve that convention in later sums over and .
Go deeper: higher-order neighbourhoods
Higher-order neighbours¶
Graph distance counts the minimum number of links needed to reach another unit. Exactly second-order neighbours are two links away, excluding first-order neighbours and the focal unit. A cumulative neighbourhood up to order two includes first- and second-order neighbours. State which version is used.
For unit 6, the first-order neighbour is 3 and the exactly second-order neighbour is 5. The cumulative set through order two is therefore {3, 5}. Matrix powers count walks and can include repeated routes and returns to the focal unit; they are not automatically the desired binary higher-order neighbourhood.

Figure 5:Higher-order neighbourhoods around Chong Boon. The upper panels show exactly second order; the lower panels combine first and second order. Compare these different sets before interpreting an order parameter.
Topology is not a display detail¶
Small gaps, overlaps or generalised coastlines can create missing or spurious contacts. Use geometries suitable for the analysis and inspect the graph. The Peninsular Malaysia income maps use generalised display outlines; those outlines should not be used to infer exact shared-border adjacency. Island units also require an explicit decision: lack of land contact need not imply lack of a meaningful geographical connection.
Distance-based relationships¶
A binary distance band connects observations whose representative locations are within a threshold :
This expression assumes distinct representative coordinates. Coincident locations require a separate rule, rather than silently excluding a pair because its distance is zero. For polygon data, specify whether distance is between centroids, interior points, population centres or another representation. A geometric centroid may fall outside an irregular polygon and does not necessarily represent where people live.
A fixed distance band has a consistent distance threshold but can produce very different neighbour counts in dense and sparse regions. It may leave some units without neighbours. Straight-line distance also need not represent travel or environmental connectivity across barriers.

Figure 6:Fort Canning, Singapore, with a 1,200 m distance band. Membership is based on representative points falling within the displayed threshold; a polygon can be selected without sharing a border with the focal polygon.

Figure 7:Fort Canning has 16 neighbours at 1,200 m and 23 at 1,500 m in this illustration; Holland Road has zero and one respectively. Increasing the threshold changes the selected set. Inspect the thresholds and representative locations rather than interpreting polygon size as distance.
Go deeper: distance-decay weights
Distance-based weights need not be binary. For distinct locations, one option is inverse-distance weighting within a stated cutoff:
Set and define how coincident points are handled before using this expression. A larger exponent gives nearer neighbours greater relative weight. A distance band selects who contributes; a decay function additionally determines how contribution varies with distance. They are separate choices.
Use projected metric coordinates suitable for the region, or a documented geodesic calculation. A threshold in metres cannot be applied directly to unprojected longitude and latitude as if degrees were metres. For a road-travel question, a network travel-time relationship may be more appropriate than Euclidean distance.
k-nearest-neighbour weights¶
A k-nearest-neighbour (kNN) rule selects the closest other observations for each focal unit. With enough observations and an explicit tie rule, each row has outgoing neighbours, but the distance to the furthest selected neighbour varies.
Consider four synthetic points on a line at 0, 1, 3 and 10 km. With , their directed selections are A→B, B→A, C→B and D→C. C selects B, but B does not select C. Thus kNN weights need not be symmetric even though the underlying distance is symmetric. The selected distance ranges from 1 km to 7 km in this example.
Choosing avoids empty outgoing neighbour sets, but does not guarantee that the entire graph is connected. Separate groups can select neighbours only within themselves. Equal-distance ties and coincident coordinates need documented handling; arbitrary coordinate jitter changes the geometry and should not be an unexplained default.
If a symmetric relation is required, distinguish the union rule (connect a pair if either selects the other) from the mutual rule (connect only if both select each other). Symmetrising changes neighbour counts, and a mutual rule can create isolates. libpysal’s KNN documentation describes its implementation and tie handling.

Figure 8:The Singapore kNN example selects four neighbours in the upper panels and twelve in the lower panels. Fixing the neighbour count allows the geographical reach to vary between focal locations. These membership maps do not imply symmetric directed selections.
Row standardisation changes the summary¶
The neighbour relation and its numerical transformation are distinct. Starting with binary adjacency, define . For a non-isolated row,
For general nonnegative weights, divide by the row’s positive weight sum instead. The transformed weights specify relative contribution to the focal unit’s neighbour summary. They do not demonstrate influence or causation.
In the six-unit example, row 5 assigns weight to each neighbour; row 6 assigns weight 1 to unit 3. Every nonempty row has total weight one, but each neighbour’s contribution differs. Standardisation changes a neighbour sum into an average; it does not make all geographical specifications or statistical results universally comparable.
Even a symmetric binary graph can become numerically asymmetric. Units 3 and 5 are mutual neighbours, but while . Distinguish asymmetry in whether a link exists from asymmetry in its transformed weight.
Let . For the binary matrix above, . With all six rows standardised, . The identity requires every included row to sum to one; do not apply it without checking isolates.
A worked spatial lag¶
A spatial lag is the weighted neighbour summary
For binary weights it is a sum; after row standardisation it is the mean of the selected neighbours. More generally, nonnegative weights summing to one give a weighted mean. The focal value is excluded when .
Assign the six synthetic units values :
| Unit | Neighbours | Binary lag: neighbour sum | Row-standardised lag: neighbour mean |
|---|---|---|---|
| 1 | 2, 4, 5 | 22 | |
| 2 | 1, 4, 5 | 20 | |
| 3 | 5, 6 | 22 | 11 |
| 4 | 1, 2, 5 | 16 | |
| 5 | 1, 2, 3, 4 | 20 | 5 |
| 6 | 3 | 6 | 6 |
Unit 5 has value 10 but neighbour mean 5. Unit 6 has value 12 but neighbour mean 6. A lag can differ substantially from the focal value and can hide disagreement among neighbours: a mean of 5 need not describe any individual neighbour.
For a mean-centred vector , the corresponding lag is . With nonempty row-standardised weights, . In this example , so unit 5 has deviation 3 and neighbour deviation lag . Their product is negative, a contrast contributing to Moran’s numerator. This is descriptive, not a local significance test.
A spatial lag is not a fitted prediction and does not establish that neighbouring values cause the focal value. Section 6.3 uses these products to construct the global statistic and its reference comparison.
Diagnose the graph before calculating the statistic¶
An isolate has no selected neighbours. A disconnected graph contains components with no links between them, even if no unit is isolated. Record both. An empty row cannot be standardised by division; representing its lag as zero is a software convention, not an observed neighbour average of zero.
Possible responses include revisiting a justified threshold, using a substantively suitable alternative relation, or reporting an explicit exclusion and its effect on the study population. Do not add arbitrary links solely to obtain a preferred coefficient. A graph across islands, mountain barriers or disconnected land masks deserves geographical inspection.
Match matrix row/column identifiers to table and geometry identifiers. Reordering a table without reordering its matrix assigns values to the wrong units. After dropping missing observations, reconstruct or correctly subset and restandardise the weights as required; neighbour counts can change.
For Malaysian districts, geometry quality, islands and unequal unit sizes require inspection. The Singapore illustrations show how rules change membership; the chapter’s empirical income analysis uses its own explicitly documented graph. Neither adjacency nor distance automatically represents commuting or income transmission.
Choose and report a defensible specification¶
| Rule | Held consistent by construction | Main issue to inspect |
|---|---|---|
| Rook/queen | A boundary-contact criterion | Topology, islands and unequal unit sizes |
| Distance band | A distance threshold | Isolates, variable neighbour counts and representative points |
| kNN | Outgoing neighbour count before symmetrisation | Long links, ties, asymmetry and separate components |
| Distance decay | A stated weighting function | Cutoff, exponent, distance units and coincident points |
Report the spatial support, geometry/coordinate system, neighbour rule and parameters, self-weight convention, transformation, isolates, components and data ordering. Compare a small set of justified alternatives while keeping other inputs fixed. A sensitivity result should explain how the question changes, rather than select the weights yielding the smallest p-value.
Check your reasoning¶
Self-check: Can queen neighbours share only an edge?
Feedback
Yes. Queen includes shared-edge and point-contact relationships; rook requires an edge.
Self-check: Does kNN guarantee one connected graph?
Feedback
No. Each observation can have outgoing neighbours while separate groups remain disconnected. Directed selections can also be asymmetric.
Self-check: Must row-standardised weights remain symmetric?
Feedback
No. Mutual neighbours with different neighbour counts receive different reciprocal weights. The underlying relation can still be symmetric.
Self-check: What is unit 5’s lag, and does it include its own value of 10?
Feedback
The binary lag is 20 and the row-standardised lag is 5. Its own value is excluded. The difference reflects the transformation, not a change in observations.
Self-check: Is a zero lag for an isolate the same as having neighbours whose values average to zero?
Feedback
No. The isolate has no neighbour information under that rule. A stored zero is a computational convention requiring explicit handling.
Read further and continue¶
Published methods reading: Anselin, L. (2002). Under the hood: Issues in the specification and interpretation of spatial regression models. Agricultural Economics, 27, 247–267. Read the discussion of spatial weights as a model specification; regression details extend beyond this chapter.
Contiguity: GeoDa Workbook: Contiguity-Based Spatial Weights. Examine graph diagnostics and higher-order definitions.
Distance: GeoDa Workbook: Distance-Band Spatial Weights. Compare distance thresholds and nearest-neighbour rules.
Calculation: libpysal: lag_spatial documents how the weights transformation affects the lag.
Next: Moran’s I: combine focal deviations with their spatial lags, normalise the sum, and assess it against a fixed-weights permutation reference.
- Anselin, L. (2002). Under the hood Issues in the specification and interpretation of spatial regression models. Agricultural Economics, 27(3), 247–267. 10.1111/j.1574-0862.2002.tb00120.x