Introduction
A value can be high in a region without that being meaningful — but a value that's high and surrounded by other high values, more than chance would predict, is a real spatial pattern worth investigating. ConductSpatialAutocorrelation tests for exactly that using Local Moran's I (LISA): for each location, it compares the local value against its K-nearest neighbors and classifies the result as a hotspot (High-High), coldspot (Low-Low), or spatial outlier (High-Low / Low-High), with statistical significance established through permutation testing rather than assumed.
Spatial autocorrelation analysis is essential for:
- Identifying geographic clusters of high disease incidence in epidemiology
- Detecting localized price anomalies or supply chain disruptions in logistics
- Pinpointing demographic shifts or localized sentiment patterns in intelligence analysis
- Validating environmental pollution hotspots or biodiversity pockets
- Strategic urban planning by identifying zones of extreme socioeconomic activity
- Fraud detection by identifying geographic clusters of suspicious financial activity
- Retail optimization by mapping high-performing store catchments and market potential
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
dataframerequired | pd.DataFrame | — | The input dataset containing geographic coordinates and the variable to be analyzed. |
longitude_column | str | 'lon' | The name of the column containing longitude values. Defaults to 'lon'. |
latitude_column | str | 'lat' | The name of the column containing latitude values. Defaults to 'lat'. |
value_column | str | None | The name of the numeric column to analyze for spatial patterns. If None, the function automatically selects the first numeric column that is not the latitude or longitude column. Defaults to None. |
k | int | 5 | The number of nearest neighbors to use when constructing the spatial weights matrix. Defaults to 5. |
plot | bool | False | Whether to generate and display an interactive Folium map visualization of the resulting hotspots, coldspots, and outliers. Defaults to False. |
Returns
The original DataFrame augmented with moran_i (local statistic), p_value (significance), and cluster_category (e.g., 'Hotspot (High-High)', 'Not Significant') columns.
Example
from analysistoolbox.geospatial_analysis import ConductSpatialAutocorrelation
import pandas as pd
import numpy as np
# Epidemiology: mapping clusters of high infection rates
infection_data = pd.DataFrame({
'county_id': range(100),
'lat': [40.7 + np.random.normal(0, 0.5) for _ in range(100)],
'lon': [-74.0 + np.random.normal(0, 0.5) for _ in range(100)],
'infection_rate': [10 + np.random.normal(0, 5) for _ in range(100)]
})
# Introduce a simulated hotspot
infection_data.loc[0:10, 'infection_rate'] = 50
results_df = ConductSpatialAutocorrelation(
infection_data,
value_column='infection_rate',
k=8,
plot=True
)
# Identifies the simulated hotspot and highlights significant clusters on a map