Skip to main content

Hypothesis Testing

GlobalMoranI

Global Moran's I is a measure of spatial autocorrelation, which quantifies the degree to which similar values in a dataset are spatially clustered together. The possible values of I are within the range of -1 and 1, where -1 represents strong negative autocorrelation (dissimilar values tend to cluster), 1 represents strong positive autocorrelation (similar values tend to cluster), and 0 represents no autocorrelation.

Global Moran's I is calculated within the context of neighbourhoods as defined by a given critical distance value. If two locations are within this critical distance, they are treated as neighbours and influence each other's values. If they are farther apart than this distance, they are not considered neighbours and do not directly affect each other in the analysis. Picking the right distance helps reveal meaningful spatial relationships and clustering in the data.

The GlobalMoranI class is an implementation of Global Moran's I as a hypothesis test, which mean that an associated Z-score and p-value are computed alongside I.

Importing the Class

The GlobalMoranI class is located in GeoJikuu's hypothesis_testing.autocorrelation module:

from geojikuu.hypothesis_testing.autocorrelation import GlobalMoranI

Coordinate Projection

GeoJikuu's hypothesis testing classes assume that any input coordinates have already been projected to a linear coordinate system. In addition, they require the input distance to be in the same unit as the chosen projection system, so the projection system's unit conversion will be needed as well. For example:

from geojikuu.preprocessing.projection import CartesianProjector
cartesian_projector = CartesianProjector("wgs84")

data = {
    "lat": [34.6870676, 34.696109, 34.6525807, 35.7146509, 35.6653623, 35.6856905, 
            33.5597115, 33.5716997, 33.5244701, 33.5153417, 33.5206116, 33.4866878],
    "lon": [135.5237618, 135.5121774, 135.5059984, 139.7963897, 139.7254906, 139.7514867,
            130.3818748, 130.4030704, 130.4063441, 130.4373212, 130.4841434, 130.5220605],
    "value": [2, 3, 1, 4, 4, 2, 5, 6, 5, 7, 8, 8]
}

df = pd.DataFrame.from_dict(data)

results = cartesian_projector.project(list(zip(df["lat"], df["lon"])))
df["cartesian_coordinates"] = results["cartesian_coordinates"]
unit_conversion = results["unit_conversion"]
df.head()
latlonvaluecartesian
034.687068135.5237622(-0.5867252094096281, 0.5760951446437298, 0.5690939403658662)
134.696109135.5121773(-0.5865446454704655, 0.5761508222375707, 0.5692236896905267)
234.652581135.5059981(-0.5867908125787922, 0.5765169810552485, 0.5685989032948122)
335.714651139.7963904(-0.6201191587857982, 0.5241083019965597, 0.5837488472665938)
435.665362139.7254914(-0.6198530442409449, 0.5251996831772221, 0.5830501662256676)
For more information, see: Projection Classes

Creating a GlobalMoranI Object

A GlobalMoranI object is created by passing in a DataFrame and the label of the column that contains the coordinates:

global_moran_i = GlobalMoranI(data=df, coordinate_label="cartesian")

Running the Global Moran I Analysis

Once the object has been created, the run() function can be used to perform the Global Moran I analysis on the inputted data. As input, the run() function takes the column name of the desired input field and the critical distance for which the analysis will be run. To convert the critical distance from kilometres to the projection system's unit, divide by the unit_conversion variable. Here is an example of running a Global Moran I analysis on an input field called "value" with a critical distance of 10 kilometres:

global_moran_i.run(input_field="value", critical_distance=10/unit_conversion)
Output: 
{'I': 0.7371851613422388,
 'Z-SCORE': 3.661110819297445,
 'P-VALUE': 0.00023886171708209503}

The results of the analysis indicates a statistically significant positive autocorrelation of moderate strength. We have evidence to reject the null hypothesis that the point-value pairs are randomly distributed across space (p << 0.05).