CAssociation · Guide test 252
Getis–Ord local G and G star tests
Test local clustering of high or low values under specified neighborhood definitions.
Do it in CodeSplash
In the app, set it up in Analyze with this method:
- Hot spots and local spatial patterns (LISA, Getis–Ord Gi and Gi*, LOSH) — Where on the map are the clusters, hot spots, spatial outliers or unusually variable neighborhoods?
In Hot spots and local spatial patterns (LISA, Getis–Ord Gi and Gi*, LOSH), choose Local statistic = Getis–Ord Gi*.
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 local 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.
The area whose local statistic is tested (row-major from the top left; click the map).
Alternative
Your data
Click an area to test it locallyThe heavy outline is the tested area, the dashed ones its neighbors. Click an area to test it instead; testing every area needs a multiplicity correction.
If H₀ were true
- The reference: how Gᵢ* varies across samples when H₀ is true (Gᵢ* is itself a z-value (normal approximation)).
- Your statistic, from the data above.
- The p-value: the area at least as extreme as yours (p = .140).
- The hatched rejection region at α = .050: statistics landing here reject H₀.
The formula
With your numbers
- row-standardized weights that include the area itself (G*); without it, Gᵢ
- already a z-value: positive for a hot spot, negative for a cold one
The verdict
Gᵢ* = 1.47, p = .140
p > α = .050: compatible with H₀
Flags clusters of high or low values around an area; many areas are tested, so adjust before calling a map of hot spots.
- Statistic
- 1.474
- p-value
- 0.1404
Getis–Ord local G* test on a 7 × 7 grid of 49 areas: Gᵢ* = 1.47, p = .140. The p-value is above α = .050, so the data are compatible with H₀.
Question and hypotheses
H0i: no unusual local concentration of high/low values near location i.
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
S²=n⁻¹Σxj²−x̄²; G*i includes self-weight wii, whereas Gi excludes the focal value and uses matching null moments.
Structure of the method
Compute a local weighted concentration of values and standardize it using the correct inclusion/exclusion-specific null moments. G excludes the focal observation from the corresponding sum/reference, whereas G-star includes its self-weight. The localG function returns standardized deviates rather than the raw local fraction.
Estimated and nuisance parameters
Estimate the relevant mean, variance, and local weight-sum quantities; no local effect parameter is fitted. Self-inclusion changes both observed numerator and reference moments. Current conditional G-star permutation conventions can hold the focal value fixed, so results depend on more than merely inserting a diagonal one.
Settings and design choices
Choose G or G-star, neighborhood extent, weight style, self-inclusion, analytic versus permutation calibration, alternative, and multiplicity adjustment. Verify the weight object’s self-neighbor metadata. A one-sided hotspot test and a two-sided hotspot/coldspot search are different hypotheses and require appropriately matched thresholds.
Fitting and adaptation
Rebuild weights after geographic/sample changes and record the zero-neighbor policy. Use localG_perm when actual Monte Carlo inference is intended and specify its focal-value handling. Adaptation involves a new spatial reference and calibration; changing radii repeatedly until desired hotspots appear is unadjusted model selection.
Sensitivity and robustness
Inspect extreme values, heterogeneous neighborhood sizes, boundary effects, disconnected locations, and familywise/false-discovery behavior across the map. A local high-value concentration is not synonymous with high relative deviation or a causal cluster. Report both the effect context and adjusted uncertainty rather than only standardized-score colors.
How to use and calibrate
Use the appropriate normal/permutation reference and multiplicity correction across locations.
Example application
Identify local hot spots or cold spots.
Interpretation and pitfalls
Watch out
The displayed equation is standardized G*, not raw Gi. Self-inclusion and weight conventions must match software.
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::localG(x,lw))
lws<-spdep::nb2listw(spdep::include.self(nb),style="W");print(spdep::localG(x,lws)) # G-star
"""
# 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::localG(x,lw))
lws<-spdep::nb2listw(spdep::include.self(nb),style="W");print(spdep::localG(x,lws)) # G-star
Sources
- spdep — spdep · localGAuthor documentation/source reviewed: spdep 1.4-2.search.r-project.org
- localGsearch.r-project.org
- cell2nbsearch.r-project.org
- include.selfsearch.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 252, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT252.