Skip to content
← Back to Spatial Analysis
spatial-analysisAdvanced· 6 min read

Spatial Statistics and Autocorrelation: Nearest Neighbour, Moran's I and Variograms

Why nearby values tend to be alike, how the nearest neighbour index and Moran's I measure that, how a variogram describes it, and what a simple simulation can and cannot show.

Why space needs its own statistics

Ordinary statistics assume that observations are independent. Spatial data usually breaks that assumption. Nearby places tend to be more alike than distant ones. Tobler's first law of geography says this directly: everything is related to everything else, but near things are more related than distant things.

This is called spatial autocorrelation. Positive autocorrelation means similar values cluster, as with hot rooftops next to hot rooftops. Negative means neighbours differ more than chance would give, like a checkerboard. Zero means no spatial pattern.

If you ignore it, a regression can report more confidence than the data supports, because neighbouring observations share information. Interpolation also depends on it, since estimating a value from neighbours only works if neighbours are related.

Testing a point pattern

The nearest neighbour index compares the observed mean distance from each point to its closest neighbour with the mean expected if the same number of points were placed at random in the same area.

  • An index below 1 means the points are clustered.
  • An index near 1 means the pattern is close to random.
  • An index above 1 means the points are more evenly spread than random.

The test is sensitive to the area you give it. A study window with a lot of empty land makes almost any pattern look clustered.

Moran's I

Moran's I measures autocorrelation for values attached to areas or cells. It runs from about minus 1 to plus 1. A value near plus 1 means similar values sit together, near zero means no pattern, and near minus 1 means a checkerboard.

To compute it, each cell's difference from the mean is multiplied by the average difference of its neighbours, and the sum is scaled by the variance. You must say what counts as a neighbour. Cells that share an edge, cells that touch at a corner, and all cells within a set distance each give a different result, so state your choice.

To test whether a value is larger than chance, shuffle the cell values many times, compute Moran's I each time, and see how often a shuffled value reaches the observed one. That fraction is a pseudo p-value.

The variogram

A variogram shows how the difference between two sample values grows with the distance between them. For each pair of points, the semivariance is half the squared difference in value. Averaging within distance bins gives the empirical variogram. Three numbers describe a fitted model:

TermMeaning
NuggetThe semivariance at zero distance, from measurement error and variation finer than the sample spacing
SillThe level where the curve flattens
RangeThe distance at which it flattens, beyond which points are no longer correlated

Kriging uses a fitted variogram to weight neighbours. A variogram fitted to too few pairs gives a weak model.

Cellular automata and simulation

A cellular automaton divides the map into cells with states, and updates all cells by a local rule at each step. Urban growth models use it: an open cell becomes built-up with a probability that depends on its built-up neighbours.

A model like this explains a mechanism, such as why growth fills in around existing development. It becomes a forecast only after calibration against past maps and validation on another period. Rules and parameters picked to show the idea give a picture, not a prediction.

Example: hospitals and temperature

In the QGIS series, 1,146 hospital points in Bengaluru give a nearest neighbour index of about 0.53, with an observed mean distance of 248 metres against 469 metres expected at random. This is clustering, as expected, since hospitals follow population and roads. Land surface temperature on a 1 km grid gives Moran's I of about 0.60, and none of 499 shuffled versions came near it. A spherical variogram fitted to the temperature samples gave a range of about 7 kilometres, so points farther apart than that behave as unrelated.

Common mistakes

  • Running statistics that assume independence on spatially autocorrelated data.
  • Reporting Moran's I without stating how neighbours were defined.
  • Running a nearest neighbour test on a window with large empty areas.
  • Fitting a variogram to too few points or too few pairs per bin.
  • Presenting a simulation with invented parameters as a forecast.
  • Forgetting that results depend on cell size and extent.

Glossary

TermMeaning
Spatial autocorrelationThe tendency of nearby values to be similar or different
Nearest neighbour indexObserved mean nearest distance divided by the mean expected at random
Moran's IA measure of autocorrelation of values across neighbours
VariogramA plot of semivariance against distance
Cellular automatonA grid of cells updated by local rules
CalibrationAdjusting a model's parameters so it matches past observations

Practise it

The tutorial Spatial statistics and simulation computes these on Bengaluru data, using a QGIS tool for the first and short Python code for the rest.

Test yourself

1. What does a nearest neighbour index of 0.5 suggest?

The points are clustered, since the observed nearest distances are about half of what random placement would give.

2. Why must you state how neighbours were defined for Moran's I?

Different definitions, such as shared edges or a distance band, give different values.

3. What does the range of a variogram tell you?

The distance beyond which samples are no longer correlated.

Quick quiz

1. Moran's I is close to plus 1. What does it mean?
2. Which part of a variogram is the semivariance at zero distance?
3. What must happen before a cellular automaton is used as a forecast?
0 of 3 answered

Key takeaways