CAssociation · Guide test 248
Global Moran I test
Tests spatial autocorrelation of a measured attribute under a specified spatial weighting scheme.
Do it in CodeSplash
In the app, set it up in Analyze with this method:
- Global spatial autocorrelation (Moran's I, Geary's C, Getis–Ord G, join counts) — Do similar values sit closer together on the map than chance alone would place them?
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
A side × side grid of areas; neighbors share an edge (rook), weights row-standardized.
Simultaneous autoregression y = ρWy + ε: positive ρ makes neighbors alike; 0 is no dependence.
Raises the center block by this much: a local cluster of high values.
Multiplies the noise in the center block: local heterogeneity in spread.
Alternative
Your data
Click an area to test it locallyDarker areas have higher values; neighbors share an edge.
If H₀ were true
- The reference: how z varies across samples when H₀ is true (normal approximation under randomization).
- Your statistic, from the data above.
- The p-value: the area at least as extreme as yours (p = .073).
- The hatched rejection region at α = .050: statistics landing here reject H₀.
The formula
With your numbers
- row-standardized rook weights: each area's edge-sharing neighbors
- deviations from the mean
- 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 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
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.
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()
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
- spdep — spdep · moran.testAuthor documentation/source reviewed: spdep 1.4-2.search.r-project.org
- spdep — spdep · moran.mcAuthor documentation/source reviewed: spdep 1.4-2.search.r-project.org
- moran.testsearch.r-project.org
- moran.mcsearch.r-project.org
- cell2nbsearch.r-project.org
- nb2listwsearch.r-project.org
- 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.