Skip to content

CAssociation · Guide test 250

Getis–Ord global G test

Tests spatial concentration of high or low attribute values.

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 = 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

7

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

0.20

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

1.5

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
12.707.63

Darker areas have higher values; neighbors share an edge.

If H₀ were true

z = −0.38
  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 = .701).
  4. The hatched rejection region at α = .050: statistics landing here reject H₀.

The formula

G=∑i∑j≠iwijxixj∑i∑j≠ixixj,z=G−E(G)Var(G),E(G)=S0n(n−1)G=\frac{\sum_i\sum_{j\ne i}w_{ij}x_ix_j}{\sum_i\sum_{j\ne i}x_ix_j},\qquad z=\frac{G-E(G)}{\sqrt{\mathrm{Var}(G)}},\quad E(G)=\frac{S_0}{n(n-1)}

With your numbers

G=0.02,E(G)=0.02,z=(−0.38)G = 0.02,\quad E(G) = 0.02,\quad z = (-0.38)
xi≥0x_i\ge 0
non-negative values such as counts or rates
GG
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 H0.

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

G=∑i≠jwijxixj∑i≠jxixjG=\frac{\sum_{i\ne j}w_{ij}x_ix_j}{\sum_{i\ne j}x_ix_j}

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.

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::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()
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::globalG.test(abs(x),spdep::nb2listw(nb,style="B"),alternative="greater"))

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 250, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT250.