CAssociation · Guide test 250
Getis–Ord global G test
Tests spatial concentration of high or low attribute values.
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 = Getis–Ord G.
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 · Getis–Ord global G 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 = .701).
- The hatched rejection region at α = .050: statistics landing here reject H₀.
The formula
With your numbers
- non-negative values such as counts or rates
- the share of all cross-products that fall between neighbors
The verdict
z = −0.38, p = .701, G = 0.02
p > α = .050: compatible with H₀
Effect size: global G G = 0.021
Separates hot spots (high next to high, z > 0) from cold spots (z < 0), which Moran's I treats alike. It needs non-negative values.
- Statistic
- −0.383
- p-value
- 0.7015
Getis–Ord global G test on a 7 × 7 grid of 49 areas: z = −0.38, p = .701, G = 0.02. The p-value is above α = .050, so the data are compatible with H₀.
Question and hypotheses
H0: no spatial clustering of high or low values under random labeling.
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. Standard interpretations usually assume nonnegative attributes.
Formula
Parameters and notation
wij commonly indicate proximity within a chosen distance; no self-pairs. Null expectation is S0/[n(n−1)] for fixed zero-diagonal weights.
Structure of the method
Aggregate weighted products of neighboring attribute values and divide by the sum over all distinct pairs, then compare with random-labeling expectation and variance. Unlike centered autocorrelation statistics, global G is designed to describe concentration of high/low values and depends on the attribute’s meaningful origin.
Estimated and nuisance parameters
Estimate raw attribute moments and denominator terms required by the analytic variance. The spatial graph and distance band are specified inputs. There is no learned hotspot intensity parameter; a standardized G score is evidence relative to a null, not an estimated causal effect or universal measure comparable across arbitrary transformations.
Settings and design choices
Choose proximity distance, binary versus other weights, self-pair exclusion, alternative, and nonnegative measurement scale. Adding a constant or taking absolute values can change the substantive question. The example uses abs(x) to create nonnegative values; this is a synthetic convenience, not a recommended transformation for all real signed attributes.
Fitting and adaptation
Adapt by selecting a meaningful nonnegative attribute and graph before inference, then evaluate the denominator and null moments. If testing multiple distance bands, predefine a primary band or calibrate the broader search. For Monte Carlo inference, permute labels consistently while holding the chosen graph fixed.
Sensitivity and robustness
Check zero/near-zero denominators, concentration in a few extreme observations, geographic boundaries, and scale/origin sensitivity. A global result can conceal separated local hotspots or offsetting concentrations. Standard high/low interpretation should not be carried over mechanically to residuals, signed returns, or arbitrary centered scores.
How to use and calibrate
Standardize using the appropriate analytic null variance or use label permutations.
Example application
Assess whether high regional values cluster globally.
Interpretation and pitfalls
Watch out
Negative values, zero denominators and alternative distance thresholds can change meaning or invalidate usual interpretations.
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::globalG.test(abs(x),spdep::nb2listw(nb,style="B"),alternative="greater"))
"""
# 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::globalG.test(abs(x),spdep::nb2listw(nb,style="B"),alternative="greater"))
Sources
- spdep — spdep · globalG.testAuthor documentation/source reviewed: spdep 1.4-2.search.r-project.org
- globalG.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 250, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT250.