Sebastián Baeza-González · Posts · Publications · Projects · Conferences · About · Español · 日本語
How do we measure similarity over space? Moran's I and Geary's C, step by step
June 10, 2026
An animated review of the logic behind the equations for Moran's I and Geary's C, and why they sometimes point to different measurements and interpretations.
If we look at any variable on a map (unemployment by district, rents by neighbourhood, soil moisture by areal unit) we will always try to find patches and patterns. High values gather here, low values over there. Spatial autocorrelation is, simply, the formal definition of that observational instinct: a way of asking with numbers, and not by eye, do similar values sit near each other more than chance would allow?
In this post we walk through the two classic answers to that question — Moran's I and Geary's C — first in their global version (one number for the whole map) and then local (one number for each areal unit). Every step of the calculation is animated, because the formulas look far more fearsome than the ideas they contain (mathematical definitions always scared me). If you can subtract an average and multiply two numbers, you can follow everything that comes next.
Three maps, three personalities
Quantitative geography rests on an observation made by Waldo Tobler: everything is related to everything else, but near things are more related than distant things. Spatial autocorrelation measures how much a particular map obeys (or defies) that observation. There are only three possibilities:
Positive spatial autocorrelation (left): similar values cluster. None (middle): values land anywhere. Negative (right): neighbours tend to be opposites, like a checkerboard. The two indicators in this post are nothing more than ways of measuring those patterns.
Moran's I and Geary's C answer the same question, but they observe and pose that question in slightly different ways — and that difference is the most useful thing you can understand about them. Before introducing them, we first need to define two features.
Feature 1: who counts as a neighbour?
Saying that "the near is more related" forces us to define what near means. We do this with a spatial weights matrix, written $W$. It sounds important, but it is just a table with one row per place (though you can also think of it as a list), where $w_{ij} = 1$ if places $i$ and $j$ are neighbours and $0$ if they are not.
Here neighbours share an edge ("rook" contiguity, like the chess piece). Counting diagonal touches too is called "queen" contiguity; you can also define neighbours by distance. The choice is yours — and it genuinely affects the result, so report it, or try different combinations to confirm how robust your results are.
Besides defining who we consider as neighbours, we must standardise those neighbourhoods by row. This is known as row-standardised weights (each row of $W$ rescaled to sum to 1), which turn "the sum over my neighbours" into "the average of my neighbours". Software packages (GeoDa, R, PySAL) call this style "W". For the test example that follows we use binary 0/1 weights ("B") because they make the arithmetic a bit simpler.
Feature 2: deviations from the mean
Both indicators start by anchoring every value to the map-wide average. This is the test map we will use for the rest of this post: nine districts, values $9, 8, 7, \dots, 1$, arranged with the high values towards the north-west.
From values to deviations. After this step the map no longer says "9" or "1" — it says "4 above average" (deep red) or "4 below average" (deep blue). Everything both indicators do happens on this red-and-blue map.
In symbols: $z_i = x_i - \bar{x}$. That's all. With our nine values the mean is $\bar{x} = 5$, so the deviations run from $+4$ down to $-4$. With this we can continue the calculation.
Moran's I: do neighbours agree about the mean?
Moran's idea is simple but powerful. Take every pair of neighbours $i$ and $j$ and multiply their deviations $z_i \times z_j$. Notice what that multiplication does:
- both above the mean → positive × positive = positive
- both below the mean → negative × negative = positive (minus times minus is plus!)
- on opposite sides → positive × negative = negative
Each pair of neighbours thus contributes a value: "we are similar" (+) or "we are opposites" (−). Moran's I adds up the votes.
Three of the twelve neighbouring pairs, then the total. Notice the middle step: one pair contributes "opposites" and the running total retreats. On a clustered map the + values sweep the board; on a checkerboard the − votes win and the total goes negative.
That sum — here $+78$ — is the core of Moran's I. The published formula translates this idea into mathematical language:
$$ I = \underbrace{\frac{n}{S_0}}\_{\text{house-keeping}} \cdot \frac{\overbrace{\sum_i \sum_j w_{ij} z_i z_j}^{\text{the animation above}}}{\underbrace{\sum_i z_i^2}\_{\text{unit cleanup}}} $$
Read like a cooking recipe:
- $\sum_i \sum_j w_{ij} z_i z_j$ — the vote count you just watched. The weights $w_{ij}$ simply switch off every pair that is not neighbours.
- $\sum_i z_i^2$ — divides by the overall variability of the data, so that a map measured in pesos and the same map measured in dollars give the same $I$.
- $n / S_0$ — divides by the number of places ($n = 9$) and the total weight ($S_0 = 24$ here: 12 pairs, each counted in both directions), so big maps and small maps are comparable.
For our test map: $I = \frac{9}{24} \cdot \frac{78}{60} = +0.49$. Positive, and with plenty of margin — the high values really are clustered.
How to read the number. $I$ usually falls between $-1$ and $+1$, like a correlation. However: the value expected on a random map is not $0$ but $E[I] = -1/(n-1)$ — with only nine areas, that is $-0.125$. (The intuition: no value can be its own neighbour, so by pure bookkeeping every place is compared against a set that is missing itself, which drags the expectation a bit below zero. With many observations this becomes almost zero.)
Geary's C: how big is the jump between neighbours?
Geary's alternative never asks about the mean. It walks every pair of neighbours and measures the distance between them directly: $(x_i - x_j)^2$. Squaring does two jobs: it removes the sign (a distance of $-4$ and one of $+4$ are equally "different") and it punishes big distances far more than small ones — a distance of 4 counts $16$ times more than a distance of 1.
Geary's C literally adds up little squares: each pair of neighbours contributes a square whose side is the distance between them. A clustered map is made of gentle steps (tiny squares); a checkerboard is made of much larger distances (huge squares).
The full formula, once again, is the translation of this idea:
$$ C = \frac{n-1}{2 S_0} \cdot \frac{\sum_i \sum_j w_{ij} (x_i - x_j)^2}{\sum_i z_i^2} $$
The numerator is the set of squares you just watched ($140$ for our example map); the rest rescales it against the data's overall variability, exactly as before. Our test map gives $C = \frac{8}{48} \cdot \frac{140}{60} = 0.39$.
How to read the number — and here is the heart of the matter. Geary's C is calibrated so that 1 means "no spatial pattern", not 0:
- $C 1$ (up to about 2) → neighbours are more different than expected by chance → negative spatial autocorrelation
In other words, Moran and Geary run in opposite directions: when clustering goes up, $I$ rises but $C$ falls. Watch them move together:
The same nine numbers, two different results. As the map flips from clustered to checkerboard, the two triangles slide in opposite directions — Moran's I falls below its random benchmark while Geary's C climbs above 1. They agree on the verdict; they just speak different languages.
So why have two indicators?
Because they genuinely capture different things, and on real (messier) maps they can disagree in informative ways:
The same pair of neighbours, two readings. Moran relates each value to the map-wide mean and asks whether the pair agrees; Geary ignores the mean entirely and measures the difference between them. Moran is a (spatial) cousin of correlation; Geary is a cousin of distance.
Practical consequences of that difference:
- Moran's I is a global conversation with the mean. It is smoother, less troubled by extreme values, and the default standard in most studies.
- Geary's C is built from distances between pairs, so it reacts more strongly to sharp local contrasts and boundaries — a handful of dramatic values between neighbours can move $C$ with hardly a strong change in $I$.
- If both agree (as in our test map: $I = +0.49$, $C = 0.39$), you can rest easy. If they disagree noticeably, your map probably mixes broad trends with marked local breaks — which is already a finding worth mapping. The local indicators below tell you where.
"Is that +0.49 actually impressive?" — the shuffle test
A number alone proves nothing: even random maps fluctuate. The standard check is honest and easy to understand. Take your nine values, scramble them across the map, and recompute $I$. Do it 999 times (or as many as your computer can handle). If your observed value sits comfortably inside the pile of random values, your "pattern" is the kind chance produces all the time. If it sits far outside, chance is a poor explanation.
The permutation test (Monte Carlo simulations). The bell of simulated values is centred near the expected −0.125, and only 1 random arrangement in 1,000 reached +0.49 — a pseudo p-value of 0.001. What is special is the geography of the values, not the values themselves.
The resulting pseudo p-value is simply "the fraction of permutations that did as well as your map (counting your own map)". No distribution tables, no assumptions of theoretical bell curves (analytical approximation) — only the bluntness of could chance have drawn this map? The same test works identically for Geary's C and for every local indicator that comes next.
Going local: one number per place
A global $I$ of $+0.49$ says the map clusters — but not where. Anselin's Local Indicators of Spatial Association (LISA) split the global vote into one score per place. The local I of place $i$ is, no more and no less, that place's contribution to the vote count you already saw:
$$ I_i = \frac{z_i}{m_2} \sum_j w_{ij} z_j \qquad\text{with } m_2 = \tfrac{1}{n}\sum_k z_k^2 $$
In words: my deviation × (the combined deviation of my neighbours). The two signs that enter that product give every place one of four labels — and a practical way to see it is the Moran scatterplot:
Each district plotted by its own deviation (horizontal) against its neighbours' average deviation (vertical). Our three big positives land in HH, the low corner lands in LL, and the "4" — a low value surrounded by highs — sits alone in LH. With row-standardised weights, the slope of the fitted line is Moran's I (0.54 here; our binary-weights version gave 0.49 — the same story, with a different result).
The four quadrants are the entire vocabulary of LISA maps:
- HH (high-high) — high value, high neighbours: the heart of a hot spot ($I_i > 0$)
- LL (low-low) — low value, low neighbours: the heart of a cold spot (also $I_i > 0$ — minus times minus!)
- LH (low-high) — a low value surrounded by highs: a spatial outlier ($I_i
Three views of the same nine numbers. The local Moran map names the clusters and flags the outlier; the local Geary map traces the frontier between them. In real work, every coloured cell must also pass its own shuffle test — and since you are running one test per place, results are filtered with a multiple-testing correction (for example, a false discovery rate) before declaring any cluster.
A bookkeeping detail that closes the circle: the local Moran I's sum back (up to a constant) to the global $I$, and the local Geary c's to the global $C$. That is precisely Anselin's definition of a LISA: the global verdict is, literally, the sum of the local particularities.
The cheat sheet (summary)
| | Moran's I | Geary's C | |---|---|---| | Core question | Are neighbours on the same side of the mean? | How far apart are neighbours? | | Building block | cross-product $z_i z_j$ | squared distance $(x_i - x_j)^2$ | | "No pattern" value | $-1/(n-1) \approx 0$ | $1$ | | Clustering looks like | $I$ well above expected (towards $+1$) | $C$ well below $1$ | | Dispersion looks like | $I$ well below expected (towards $-1$) | $C$ above $1$ (up to $\sim 2$) | | Personality | smooth, mean-anchored, the default option | sensitive to edges and sharp local contrasts | | Local version | $I_i$ → HH / LL / HL / LH cluster maps | $c_i$ → similarity vs. contrast maps | | Significance | shuffle (permutation) test for both, with multiple-testing care for the locals | same |
Try it with your own data
Five lines in either language. In R, with spdep:
Or in Python, with libpysal + esda:
Whatever you run, the three honest questions remain the ones this post animated: who did I count as a neighbour?, what does the indicator actually compare?, and could a shuffle have done just as well? If you can answer them, the program's output holds no mysteries.
Tobler, W. (1970). A computer movie simulating urban growth in the Detroit region. Economic Geography, 46, 234–240. Moran, P. A. P. (1950). Notes on continuous stochastic phenomena. Biometrika, 37(1/2), 17–23. Geary, R. C. (1954). The contiguity ratio and statistical mapping. The Incorporated Statistician, 5(3), 115–146. Anselin, L. (1995). Local Indicators of Spatial Association — LISA. Geographical Analysis, 27(2), 93–115. Anselin, L. (2019). A local indicator of multivariate spatial association: extending Geary's c. Geographical Analysis, 51(2), 133–150.