moran

moran(
    data,
    variable,
    year=None,
    *,
    w=None,
    permutations=999,
    seed=12345,
    title=None,
    gdf=None,
    ref=None,
)

Global Moran’s I of a variable: is it clustered in space?

Parameters

Name Type Description Default
data A dataset id, or a panel with geo_id (and year), e.g. from load required
variable str The numeric column to test required
year The year to test (default: the last with data), or "all" for Moran’s I in every year, on the units that have data in all of them None
w Spatial weights from weights (default: queen contiguity among the units with data) None
permutations int Random permutations behind the pseudo p-value 999
seed int | None Makes the permutations reproducible (None: leave the random state alone) 12345
title str | None The figure title None
gdf Boundaries to use instead of the project’s (a GeoDataFrame with geo_id) None

Returns

Name Type Description
result object For one year, a result with .moran_i, .p_sim, .z_sim, .fig (the Moran scatterplot: each unit’s standardized value against its neighbours’ mean), .df (one row per unit with its quadrant) and .interpret(). For year="all", a result with .df (one row per year: moran_i, p_sim, z_sim), .fig (Moran’s I over time) and .interpret().

Example

!pip install -q geo4bolivia
import geo4bolivia as geo

res = geo.moran("sdg", "index_sdg", year=2024)
print(res.interpret())
print(geo.moran("sdg", "index_sdg", year="all").df)   # Moran's I in each year
res.fig

Global Moran’s I for Sustainable Development Index, IDS (0-100) in 2024 is 0.468, against an expectation of -0.00292 under spatial randomness — statistically significant at the 1% level (pseudo p = 0.001 from 999 permutations, under queen contiguity (1 island(s) attached to nearest neighbor), row-standardized, n=343).

The dependence is positive: similar values cluster in space — high values sit next to high values and low next to low, so the map shows contiguous patches rather than a random scatter.

261 of 343 units (76%) fall in the clustering quadrants of the scatter (High-High or Low-Low); the rest are surrounded by neighbors unlike themselves. The slope of the fitted line equals Moran’s I under row-standardized weights, so a steeper line means stronger clustering.

These are associations, not causal effects. A causal reading needs a research design.

   year   moran_i      z_sim  p_sim  n_obs
0  2012  0.432470  12.748494  0.001    343
1  2024  0.467933  13.782523  0.001    343