CAssociation · Guide test 249
Geary C test
Tests spatial autocorrelation using squared differences between neighboring observations.
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 = Geary's C.
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 · Geary C 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 = .068).
- The hatched rejection region at α = .050: statistics landing here reject H₀.
The formula
With your numbers
- squared differences between neighbors: small when neighbors are alike
- its value with no spatial association; below 1 means clustering
The verdict
z = 1.83, p = .068, C = 0.81
p > α = .050: compatible with H₀
Effect size: Geary's C C = 0.807
More sensitive than Moran's I to local differences between neighbors; z is oriented here so positive means like values cluster.
- Statistic
- 1.826
- p-value
- 0.0678
Geary C test on a 7 × 7 grid of 49 areas: z = 1.83, p = .068, C = 0.81. The p-value is above α = .050, so the data are compatible with H₀.
Question and hypotheses
H0: no spatial association under the specified null.
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
S0=Σwij; E0C=1 under random labeling. Small C suggests positive local similarity.
Structure of the method
Compute squared differences across weighted neighbor pairs, normalize by global variation and total weight, then compare the result with the selected randomization/normality reference. The squared-difference structure emphasizes local disagreement differently from Moran’s centered cross-products; the statistics are related diagnostics, not interchangeable scales.
Estimated and nuisance parameters
Estimate the mean/variance or higher moments needed by analytic calibration; the observed C is a normalized statistic rather than a learned spatial coefficient. The usual random-label expectation is one. Small values indicate positive local similarity, so the direction of a one-sided alternative must match that convention.
Settings and design choices
Choose symmetric versus directed graph, binary/standardized weights, neighborhood rule, zero-neighbor handling, and one/two-sided alternative. Some analytic variance formulas require symmetric weights or a valid symmetrization. Selecting neighbors according to the outcome itself changes the null and needs explicit justification.
Fitting and adaptation
For new geography or exclusions, reconstruct and align the weights before recalculating C. Use valid label permutations only if exchangeability is plausible; for fitted residuals, choose a model-aware procedure. There is no neural fine-tuning, and changing weight normalization is a new statistic specification rather than learned optimization.
Sensitivity and robustness
Inspect outliers, irregular degrees, islands, asymmetry, small samples, and the contrast between local pair differences and overall variance. Outlying adjacent observations can dominate squared differences. Report the weight matrix and null choice, and avoid interpreting C below one as a quantitative estimate of a causal neighborhood effect.
How to use and calibrate
Use a matching permutation distribution or justified analytic variance.
Example application
Detect neighboring-value differences, often with more local sensitivity than Moran I.
Interpretation and pitfalls
Watch out
The sign convention is opposite to Moran I: values below one indicate positive association.
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::geary.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::geary.test(x,lw,alternative="two.sided"))
Sources
- spdep — spdep · geary.testAuthor documentation/source reviewed: spdep 1.4-2.search.r-project.org
- geary.testsearch.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 249, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT249.