Local Spatial Autocorrelation

The local spatial autocorrelation measures the relationships between each observation and its surroundings.

Although Moran’s I statistic helps understand the overall behavior of a variable across different locations in the whole dataset, it does not explain the relationship between a specific observation and its surroundings. For example, a positive value of Moran’s I statistic indicates the presence of clusters but it does not indicate where the clusters are or explain the degree of similarity of a variable in a given location with its neighbors. The local spatial autocorrelation fills this gap as it explain the relationship between a specific observation and its surroundings.

The Local Moran’s I statistic represents the local spatial autocorrelation of a specific observation and is given by the following formula.



The Moran’s I statistic is the sum of all local Moran’s I divided by the spatial weights.

A positive local Moran’s I statistic indicates similarity with neighboring locations; it can be either a high value surrounded by high values or a low value surrounded by low values.

A negative local Moran’s I statistic represents variance with neighboring locations; it can be either a high value around low values or a low value surrounded by high values. This metric helps to identify outliers in the dataset.

The LocalMoranITest.create function inside oraclesai.analysis calculates the local Moran’s I statistic of each observation in a dataset.

See the LocalMoranITest class in Python API Reference for Oracle Spatial AI for more information.

The following code uses the LocalMoranITest.create function to calculate the local spatial autocorrelation for the MEDIAN_INCOME column of each observation in the block_groups dataset. The class uses spatial weights to obtain the values from neighboring locations and compute the local Moran’s I.

from oraclesai.analysis import LocalMoranITest
from oraclesai.weights import SpatialWeights, KNNWeightsDefinition

spatial_weights = SpatialWeights.create(block_groups["geometry"].values, KNNWeightsDefinition(k=5))  

local_moran_test = LocalMoranITest.create(block_groups, spatial_weights, column_name="MEDIAN_INCOME")

print(f"Local Moran's I: {local_moran_test.i_list[:10]}")
print(f"p-values: {local_moran_test.p_values[:10]}")

The preceding code prints the Local Moran’s I and the corresponding p-value of the first ten observations of the dataset.

Local Moran's I: [-0.09208001 -0.16105385  0.34887379  2.13410581  2.53000192  0.96564933
  0.77039582  1.04246212 -0.01040734 -0.11960612]
p-values: [0.28  0.069 0.011 0.011 0.001 0.054 0.023 0.102 0.342 0.19 ]