Skip to content

CAssociation · Guide test 248

Global Moran I test

Tests spatial autocorrelation of a measured attribute under a specified spatial weighting scheme.

Runs in CodeSplashPython (calls R) example not runR example not run

Do it in CodeSplash

In the app, set it up in Analyze with this method:

In Global spatial autocorrelation (Moran's I, Geary's C, Getis–Ord G, join counts), choose Test = Moran's I.

Do it in CodeSplash Run this test on your own data, in Python or R.

Bench

Change the design, drag the data, move α. The statistic, its reference distribution and the verdict follow.

Bench · Global Moran I test

7

A side × side grid of areas; neighbors share an edge (rook), weights row-standardized.

0.50

Simultaneous autoregression y = ρWy + ε: positive ρ makes neighbors alike; 0 is no dependence.

0.0

Raises the center block by this much: a local cluster of high values.

1.0

Multiplies the noise in the center block: local heterogeneity in spread.

0.050

Alternative

Your data

Click an area to test it locally
11.977.59

Darker areas have higher values; neighbors share an edge.

If H₀ were true

z = 1.80
  1. The reference: how z varies across samples when H₀ is true (normal approximation under randomization).
  2. Your statistic, from the data above.
  3. The p-value: the area at least as extreme as yours (p = .073).
  4. The hatched rejection region at α = .050: statistics landing here reject H₀.

The formula

I=nS0 ∑i∑jwijzizj∑izi2,z=I−E(I)Var(I),E(I)=−1n−1I=\frac{n}{S_0}\,\frac{\sum_i\sum_jw_{ij}z_iz_j}{\sum_iz_i^2},\qquad z=\frac{I-E(I)}{\sqrt{\mathrm{Var}(I)}},\quad E(I)=-\frac1{n-1}

With your numbers

I=0.17,E(I)=(−0.02), SD=0.11,z=1.80I = 0.17,\quad E(I) = (-0.02),\ \mathrm{SD} = 0.11,\quad z = 1.80
wijw_{ij}
row-standardized rook weights: each area's edge-sharing neighbors
zi=xi−xˉz_i = x_i-\bar x
deviations from the mean
Var(I)\mathrm{Var}(I)
under randomization: values shuffled over the areas

The verdict

z = 1.80, p = .073, I = 0.17

p > α = .050: compatible with H₀

Effect size: Moran's I I = 0.172

The result depends on the weights as much as on the data; state them. A positive I says values cluster on the map, not where.

Statistic
1.796
p-value
0.0726
Global Moran I test on a 7 × 7 grid of 49 areas: z = 1.80, p = .073, I = 0.17. The p-value is above α = .050, so the data are compatible with H0.

Global Moran I test on a 7 × 7 grid of 49 areas: z = 1.80, p = .073, I = 0.17. The p-value is above α = .050, so the data are compatible with H₀.

Question and hypotheses

H0: no spatial association under the chosen randomization or normality model.

Assumptions

A prespecified spatial weights/neighborhood matrix W, a clearly defined spatial null, and observations whose labels can be permuted under that null. Model residual tests require model-specific adjustments.

Formula

I=nS0∑ijwij(xi−xˉ)(xj−xˉ)∑i(xi−xˉ)2S0=∑ijwij\begin{gathered}I=\frac{n}{S_0}\frac{\sum_{ij}w_{ij}(x_i-\bar x)(x_j-\bar x)}{\sum_i(x_i-\bar x)^2}\\[5pt] S_0=\sum_{ij}w_{ij}\end{gathered}

Parameters and notation

Usually wii=0. Under random labeling E0I=−1/(n−1). Row-standardized and binary weights produce different statistics.

Structure of the method

Align an attribute vector with a prespecified neighbor/weight matrix, center the values, form the weighted cross-product, normalize by global squared deviations, and evaluate against the selected spatial null. Analytic randomization, analytic normality, and Monte Carlo labeling are different calibration routes.

Estimated and nuisance parameters

Estimate the attribute mean and scale/moments used by the chosen null variance. Spatial weights are usually design inputs rather than estimated spillover coefficients. When testing regression residuals, upstream coefficients and altered residual covariance matter; the ordinary raw-variable random-labeling formula is not automatically a regression residual test.

Settings and design choices

Choose contiguity/distance graph, distance threshold, weight style, self-neighbor exclusion, zero-neighbor policy, alternative, and permutation count. These settings define the spatial question. Testing many neighborhood radii and reporting only the strongest result requires selection adjustment, not merely a larger simulation count.

Fitting and adaptation

Adapt by constructing a scientifically justified spatial graph and ensuring row/ID correspondence after exclusions. Recompute weights consistently when the geography or sample changes. For model-adjusted residual analysis, use a matching diagnostic/calibration rather than treating fitted residuals as freely exchangeable raw labels.

Sensitivity and robustness

Inspect islands, highly unequal neighbor counts, skew/outliers, boundary regions, the modifiable-area problem, and normality-versus-randomization assumptions. Positive association means similar values tend to neighbor under the chosen graph; it neither identifies spillover direction nor proves spatial causation. Report sensitivity across defensible graphs as transparent exploration.

How to use and calibrate

Use a permutation tail or a normal approximation with the correct randomization/normality variance; specify positive, negative or two sided alternative.

Example application

Assess clustering of similar regional values.

Interpretation and pitfalls

Watch out

Spatial weights define the question. A significant I is not proof of a spillover mechanism or causation.

What changed in edition 2

  • New sections: structure of the method, estimated and nuisance parameters, settings and design choices, fitting and adaptation, sensitivity and robustness.

Python and R

Synthetic 6×6 rook-neighbor lattice; weights and null randomization choices are part of the test. Local tests require multiplicity control before declaring a map of discoveries. localG without self-neighbors is G, not G-star.

Python · invokes R

Not run — Python launcher syntax checked; R backend runtime not verified · needs Python standard library + Rscript; R packages: spdep

# Python launcher for the complete R implementation below.
# Requires Rscript on PATH and the listed R packages.
import shutil
import subprocess
rscript = shutil.which("Rscript")
if rscript is None:
    raise RuntimeError("Install R and make Rscript available on PATH.")
r_code = r"""
set.seed(2026)
nb<-spdep::cell2nb(6,6,type="rook");lw<-spdep::nb2listw(nb,style="W");x<-rnorm(36)
print(spdep::moran.test(x,lw,alternative="two.sided"))
"""
# No shell interpolation. A failed R execution raises an error in Python.
result = subprocess.run([rscript, "--vanilla", "-"], input=r_code,
                        text=True, capture_output=True)
print(result.stdout)
if result.stderr:
    print(result.stderr)
result.check_returncode()
R

Not run — Syntax checked; runtime not verified in the final environment · needs spdep

set.seed(2026)
nb<-spdep::cell2nb(6,6,type="rook");lw<-spdep::nb2listw(nb,style="W");x<-rnorm(36)
print(spdep::moran.test(x,lw,alternative="two.sided"))

Sources

Statistics guide v4 (historical):
Python: Python launcher syntax checked; R backend runtime not verified · R: Syntax checked; runtime not verified in the final environment
Reference's record:
Edition 2 review: Python: skip · R: not executed (Rscript unavailable); why not run: Python: Python-to-R bridge; Rscript is unavailable. R code was not executed. Python: Not run in the reference's review: Python-to-R bridge; Rscript is unavailable. R code was not executed. R: Reviewed but not run: R wasn't available to the reference's authors.

From the CodeSplash statistics guide (v4), entry 248, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT248.