Spatial Diagnostics
Moran's I (Global)
Tests for global spatial autocorrelation:
mr = moran_global(y, W)
# mr.I_stat — Moran's I statistic
# mr.z_stat — z-score
# mr.p_value — p-value (permutation-based)LISA (Local Moran's I)
Identifies local clusters and spatial outliers:
lisa = moran_local(y, W; n_perm=999)
# lisa.local_I — local I for each observation
# lisa.cluster_type — :HH, :LL, :HL, :LH, or :ns
# lisa.pseudo_p — pseudo p-valuesGeary's C
Alternative global measure (inversely related to Moran's I):
gc = geary_c(y, W)
# gc.C_stat < 1 → positive autocorrelation
# gc.C_stat > 1 → negative autocorrelationLM Tests
Choose between spatial lag and spatial error specifications:
lm = lm_tests(y, X_with_intercept, W)
# lm.lag — LM test for spatial lag
# lm.error — LM test for spatial error
# lm.lag_robust — Robust LM lag (controlling for error)
# lm.error_robust — Robust LM error (controlling for lag)Decision rule (Anselin 2005):
- If neither LM-lag nor LM-error is significant → OLS is fine
- If only one is significant → use that specification
- If both significant → compare robust versions
- If both robust versions significant → consider SDM