# Moran's I

In statistics, Moran's I is a measure of spatial autocorrelation developed by Patrick Alfred Pierce Moran. Spatial autocorrelation is characterized by a correlation in a signal among nearby locations in space. Spatial autocorrelation is more complex than one-dimensional autocorrelation because spatial correlation is multi-dimensional (i.e. 2 or 3 dimensions of space) and multi-directional.

## Global Moran's I

Global Moran's I is a measure of the overall clustering of the spatial data. It is defined as
    $I={\frac {N}{W}}{\frac {\sum _{i=1}^{N}\sum _{j=1}^{N}w_{ij}(x_{i}-{\bar {x}})(x_{j}-{\bar {x}})}{\sum _{i=1}^{N}(x_{i}-{\bar {x}})^{2}}}$
where
* $N$ is the number of spatial units indexed by $i$ and $j$;
* $x$ is the variable of interest;
* ${\bar {x}}$ is the mean of $x$;
* $w_{ij}$ are the elements of a matrix of spatial weights with zeroes on the diagonal (i.e., $w_{ii}=0$);
* and $W$ is the sum of all $w_{ij}$ (i.e. $W=\sum _{i=1}^{N}\sum _{j=1}^{N}{w_{ij}}$).
    Moran's I statistic computed for different spatial patterns. Using 'rook' neighbors for each grid cell, setting $w_{ij}=1$ for neighbours $j$ of $i$ and then row normalizing the weight matrix. Top left shows anti-correlation giving a negative I. Top right shows a spatial gradient giving a large positive I. Bottom left shows random data giving a value of I near 0 (or $-1/(N-1)\simeq -0.04$). Bottom right shows an 'ink blot' or spreading pattern with positive autocorrelation.

### Defining the spatial weights matrix

The value of $I$ can depend quite a bit on the assumptions built into the spatial weights matrix $w_{ij}$. The matrix is required because, in order to address spatial autocorrelation and also model spatial interaction, we need to impose a structure to constrain the number of neighbors to be considered. This is related to Tobler's first law of geography, which states that Everything depends on everything else, but closer things more so—in other words, the law implies a spatial distance decay function, such that even though all observations have an influence on all other observations, after some distance threshold that influence can be neglected.
The idea is to construct a matrix that accurately reflects your assumptions about the particular spatial phenomenon in question. A common approach is to give a weight of 1 if two zones are neighbors, and 0 otherwise, though the definition of 'neighbors' can vary. Another common approach might be to give a weight of 1 to $k$ nearest neighbors, 0 otherwise. An alternative is to use a distance decay function for assigning weights. Sometimes the length of a shared edge is used for assigning different weights to neighbors. The selection of spatial weights matrix should be guided by theory about the phenomenon in question. The value of $I$ is quite sensitive to the weights and can influence the conclusions you make about a phenomenon, especially when using distances.

### Expected value

The expected value of Moran's I under the null hypothesis of no spatial autocorrelation is
    $E(I)={\frac {-1}{N-1}}$
The null distribution used for this expectation is that the $x$ input is permuted by a permutation $\pi$ picked uniformly at random (and the expectation is over picking the permutation).
At large sample sizes (i.e., as N approaches infinity), the expected value approaches zero.
Its variance equals
    $\operatorname {Var} (I)={\frac {NS_{4}-S_{3}S_{5}}{(N-1)(N-2)(N-3)W^{2}}}-(E(I))^{2}$
where
    $S_{1}={\frac {1}{2}}\sum _{i}\sum _{j}(w_{ij}+w_{ji})^{2}$
    $S_{2}=\sum _{i}\left(\sum _{j}w_{ij}+\sum _{j}w_{ji}\right)^{2}$
    $S_{3}={\frac {N^{-1}\sum _{i}(x_{i}-{\bar {x}})^{4}}{(N^{-1}\sum _{i}(x_{i}-{\bar {x}})^{2})^{2}}}$
    $S_{4}=(N^{2}-3N+3)S_{1}-NS_{2}+3W^{2}$
    $S_{5}=(N^{2}-N)S_{1}-2NS_{2}+6W^{2}$
Values significantly below -1/(N-1) indicate negative spatial autocorrelation and values significantly above -1/(N-1) indicate positive spatial autocorrelation. For statistical hypothesis testing, Moran's I values can be transformed to z-scores.
Values of I range between ${\frac {N}{W}}w_{min}$ and ${\frac {N}{W}}w_{max}$ where $w_{min}$ and $w_{max}$ are the corresponding minimum and maximum eigenvalues of the weight matrix. For a row normalised matrix ${\frac {N}{W}}=1$.
Moran's I is inversely related to Geary's C, but it is not identical. Moran's I is a measure of global spatial autocorrelation, while Geary's C is more sensitive to local spatial autocorrelation.

## Local Moran's I

Global spatial autocorrelation analysis yields only one statistic to summarize the whole study area. In other words, the global analysis assumes homogeneity. If that assumption does not hold, then having only one statistic does not make sense as the statistic should differ over space.
Moreover, even if there is no global autocorrelation or no clustering, we can still find clusters at a local level using local spatial autocorrelation analysis. The fact that Moran's I is a summation of individual cross products is exploited by the "local indicators of spatial association" (LISA) to evaluate the clustering in those individual units by calculating Local Moran's I for each spatial unit and evaluating the statistical significance for each I$_i$. From the equation of Global Moran's I, we can obtain:
    $I_{i}={\frac {x_{i}-{\bar {x}}}{m_{2}}}\sum _{j=1}^{N}w_{ij}(x_{j}-{\bar {x}})$
where:
    $m_{2}={\frac {\sum _{i=1}^{N}(x_{i}-{\bar {x}})^{2}}{N}}$
then,
    $I=\sum _{i=1}^{N}{\frac {I_{i}}{N}}$
I is the Global Moran's I measuring global autocorrelation, I$_i$ is local, and N is the number of analysis units on the map.
LISAs can be calculated in GeoDa and ArcGIS Pro which uses the Local Moran's I, proposed by Luc Anselin in 1995.

## Uses

Moran's I is widely used in the fields of geography and geographic information science. Some examples include:
* The analysis of geographic differences in health variables.
* Characterising the impact of lithium concentrations in public water on mental health.
* In dialectology to measure the significance of regional language variation.
* Defining an objective function for meaningful terrain segmentation for geomorphological studies