Skip to content

CAssociation · Guide test 252

Getis–Ord local G and G star tests

Test local clustering of high or low values under specified neighborhood definitions.

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

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.

25

The area whose local statistic is tested (row-major from the top left; click the map).

0.050

Alternative

Your data

Click an area to test it locally
12.707.63● local |z| > 1.96(unadjusted: expect ~5%of areas by chance)

The 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

Gᵢ* = 1.47
  1. The reference: how Gᵢ* varies across samples when H₀ is true (Gᵢ* is itself a z-value (normal approximation)).
  2. Your statistic, from the data above.
  3. The p-value: the area at least as extreme as yours (p = .140).
  4. The hatched rejection region at α = .050: statistics landing here reject H₀.

The formula

Gi∗=∑jwijxj−xˉ∑jwijs[n∑jwij2−(∑jwij)2]/(n−1)G_i^*=\frac{\sum_jw_{ij}x_j-\bar x\sum_jw_{ij}}{s\sqrt{\big[n\sum_jw_{ij}^2-(\sum_jw_{ij})^2\big]/(n-1)}}

With your numbers

G25∗=1.47G^*_{25} = 1.47
wijw_{ij}
row-standardized weights that include the area itself (G*); without it, Gᵢ
Gi∗G_i^*
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: Gi* = 1.47, p = .140. The p-value is above α = .050, so the data are compatible with H0.

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

Gi∗=∑jwijxj−xˉ∑jwijS[n∑jwij2−(∑jwij)2]/(n−1)G_i^*=\frac{\sum_jw_{ij}x_j-\bar x\sum_jw_{ij}}{S\sqrt{[n\sum_jw_{ij}^2-(\sum_jw_{ij})^2]/(n-1)}}

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.

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::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()
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::localG(x,lw))
lws<-spdep::nb2listw(spdep::include.self(nb),style="W");print(spdep::localG(x,lws)) # G-star

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