Skip to content

CAssociation · Guide test 251

Local Moran I tests

Test localized spatial association and identify candidate clusters or spatial outliers; multiplicity needs attention.

Runs in CodeSplashPython (calls R) example not runR example not run Corrected in edition 2

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 = Local Moran's I (LISA).

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 · Local Moran I 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

z = 1.04
  1. The reference: how z varies across samples when H₀ is true (normal approximation under conditional randomization; test the area chosen in advance).
  2. Your statistic, from the data above.
  3. The p-value: the area at least as extreme as yours (p = .300).
  4. The hatched rejection region at α = .050: statistics landing here reject H₀.

The formula

Ii=zim2∑jwijzj,m2=1n∑kzk2,zi=Ii−E(Ii)Var(Ii)I_i=\frac{z_i}{m_2}\sum_jw_{ij}z_j,\qquad m_2=\frac1n\sum_kz_k^2,\qquad z_i=\frac{I_i-E(I_i)}{\sqrt{\mathrm{Var}(I_i)}}

With your numbers

I25=0.60,E=(−0.03), SD=0.61,z=1.04I_{25} = 0.60,\quad E = (-0.03),\ \mathrm{SD} = 0.61,\quad z = 1.04
Ii>0I_i > 0
the area resembles its neighbors (high–high or low–low)
Ii<0I_i < 0
it differs from them (a spatial outlier)
Var(Ii)\mathrm{Var}(I_i)
conditional randomization: the area's value fixed, the others shuffled

The verdict

z = 1.04, p = .300, Iᵢ = 0.60

p > α = .050: compatible with H₀

Effect size: local Moran Iᵢ = 0.599

One test per area: testing them all needs a multiplicity correction, and the dots on the map are unadjusted. Neighboring tests overlap, so they are not independent.

Statistic
1.036
p-value
0.3001
Local Moran I test on a 7 × 7 grid of 49 areas: z = 1.04, p = .300, Ii = 0.60. The p-value is above α = .050, so the data are compatible with H0.

Local Moran I test on a 7 × 7 grid of 49 areas: z = 1.04, p = .300, Iᵢ = 0.60. The p-value is above α = .050, so the data are compatible with H₀.

Question and hypotheses

H0i: location i has no unusual local spatial association under a specified conditional/total randomization 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

Ii=xi−xˉm2∑jwij(xj−xˉ)m2=n−1∑j(xj−xˉ)2\begin{gathered}I_i=\frac{x_i-\bar x}{m_2}\sum_jw_{ij}(x_j-\bar x)\\[5pt] m_2=n^{-1}\sum_j(x_j-\bar x)^2\end{gathered}

Parameters and notation

Choose whether xi is held fixed during conditional permutations. High-high/low-low and high-low/low-high labels use both signs, not Ii alone.

Structure of the method

At each location, multiply its centered value by its weighted neighbor lag, normalize by the declared global variance, and compare with a location-specific null. Conditional randomization fixes the focal observation while varying neighbors; total randomization treats all labels differently, producing distinct expectations and variances.

Estimated and nuisance parameters

Estimate global mean/variance and local null moments or simulated reference summaries. No local regression coefficient is learned. High-high/low-low versus high-low/low-high categories additionally use the signs of the focal deviation and spatial lag; a significant positive statistic alone does not distinguish the two cluster types.

Settings and design choices

Choose graph/weights, conditional versus total null, n versus n-1 variance convention, analytic versus permutation inference, number of simulations, and multiplicity control. The baseline localmoran call computes analytic moments, not an actual Monte Carlo permutation distribution; localmoran_perm is the separately documented simulation route.

Fitting and adaptation

Ensure vector IDs match graph IDs and recompute the analysis after missing-value exclusions. For permutation variants, fix the seed and state focal-value handling. If local labels are chosen after a global test, explain the inferential strategy; a significant global result does not automatically license unadjusted testing at every location.

Sensitivity and robustness

Inspect neighbor counts, islands, outliers, skewed conditional distributions, p-value discreteness, and spatial dependence among local tests. Use an appropriate multiplicity procedure and avoid declaring every unadjusted colored location a confirmed cluster. Neighborhood and administrative-boundary changes can alter both the statistic and its local interpretation.

How to use and calibrate

Use location-specific permutation distributions and address multiplicity across tested locations.

Example application

Locate clusters and spatial outliers after a global spatial analysis.

Interpretation and pitfalls

Watch out

A map of unadjusted local p values can contain many false discoveries. Conditional and total randomization p values differ.

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.
  • Rewritten in the review: how to use and calibrate.
  • How to use and calibratesearch.r-project.org

    Distinguish analytic localmoran from the separately documented localmoran_perm function.

    Corrected text

    Use location-specific null moments or permutation distributions, explicitly identifying conditional versus total randomization, and address multiplicity across locations. The supplied spdep::localmoran call uses analytic conditional-randomization moments by default; use spdep::localmoran_perm when actual Monte Carlo permutation p values are intended.

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::localmoran(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()
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::localmoran(x,lw,alternative="two.sided"))

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