lisa_transitions(
data,
variable,
first=None,
last=None,
*,
w=None,
permutations=999,
seed=12345,
alpha=0.05,
tiles='carto-positron',
title=None,
gdf=None,
ref=None,
)
Transitions between local Moran (LISA) types: did the hot spots and cold spots persist?
Runs lisa in two years on the same units and the same weights, and counts how the units moved between the types High-High, Low-High, Low-Low, High-Low and Not significant.
Parameters
| data |
|
A dataset id, or a panel with geo_id and year, e.g. from load |
required |
| variable |
str |
The numeric column to analyse |
required |
| first |
|
The two years to compare (default: the first and last with data); only the units with a value in both are used |
None |
| last |
|
The two years to compare (default: the first and last with data); only the units with a value in both are used |
None |
| w |
|
Spatial weights from weights (default: queen contiguity among the units with data) |
None |
| permutations |
int |
Random permutations behind each unit’s pseudo p-value |
999 |
| seed |
int | None |
Makes the permutations reproducible |
12345 |
| alpha |
float |
Significance level below which a unit is assigned to a cluster |
0.05 |
| tiles |
str | None |
The basemap style of the map (None: no basemap) |
'carto-positron' |
| title |
str | None |
The title of the matrix figure |
None |
| gdf |
|
Boundaries to use instead of the project’s (a GeoDataFrame with geo_id) |
None |
Returns
|
result object |
A result with .df (one row per unit: cluster_<first>, cluster_<last>, moved and the transition in words), .matrix (units by type in the first year, rows, and in the last year, columns; always the five types, in the same order), .shares (each row as shares of its total; empty rows are missing), .fig (the matrix as a heatmap: counts in the cells, coloured by the share of the row), .fig_map (the types in the last year, with the units that changed type outlined), .n_units, .n_stayed, .n_moved, .share_stayed, the global Moran’s I of each year (.moran_i_first, .moran_i_last, with .p_sim_first and .p_sim_last) and .interpret(). |
Example
!pip install -q geo4bolivia
import geo4bolivia as geo
res = geo.lisa_transitions("sdg", "index_sdg") # ~2012 to ~2024
print(res.interpret())
res.fig
Local Moran statistics (LISA) of Sustainable Development Index, IDS (0-100) were computed in 2012 and in 2024 for the same 343 units, under queen contiguity (1 island(s) attached to nearest neighbor), row-standardized, n=343, and each unit was assigned to a type at the 0.05 level. Global Moran’s I is 0.432 in 2012 (pseudo p = 0.001) and 0.468 in 2024 (pseudo p = 0.001): the overall clustering of similar values changed little.
275 of 343 units (80%) are of the same type in both years and 68 changed type. Of the 104 units in a significant cluster or outlier in 2012, 71 kept their type, 23 are no longer significant in 2024 and 10 switched to another type. 35 units that were not significant in 2012 belong to a cluster or are an outlier in 2024.
Of the 46 High-High hot spots (high values surrounded by high values) of 2012, 39 are still High-High in 2024, a year with 60 of them. Of the 44 Low-Low cold spots (low values surrounded by low values) of 2012, 30 are still Low-Low in 2024, a year with 45 of them. The most common change is from Not significant to High-High (17 units).
Read the changes with care. A unit’s type depends on whether its pseudo p-value is below the threshold, computed unit by unit without a multiple-testing adjustment, so moves to and from Not significant can come from borderline p-values. High and low are relative to the mean of each year, and a unit can change type because its neighbours’ values changed while its own did not.
These are associations, not causal effects. A causal reading needs a research design.