netneurotools.spatial.morans_i
- netneurotools.spatial.morans_i(annot, weight, use_numba=False, standardized=False)[source]
Calculate Moran’s I for spatial autocorrelation.
- Parameters:
annot (array-like, shape (n,)) – Array of annotations to calculate Moran’s I for.
weight (array-like, shape (n, n)) – Spatial weight matrix. Note that we do not explicitly check for symmetry in the weight matrix, nor zero-diagonal elements.
use_numba (bool, optional) – Whether to use numba for calculation. Default: True (if numba is installed).
standardized (bool, optional) – Whether to standardize the Moran’s I statistic with respect to its expectation and variance under the null assumption that annotation values are sampled from a normal distribution.
- Returns:
morans_i – Moran’s I value for the given annotations and weight matrix.
- Return type:
See also
netneurotools.spatial.spatial_stats.local_morans_iNotes
Moran’s I [1,2] is calculated as:
\[I = \frac{n}{\sum_{i=1}^{n} \sum_{j=1}^{n} w_{ij}} \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 observations, \(w_{ij}\) is the spatial weight between observations \(i\) and \(j\), \(x_i\) is the annotation for observation \(i\), and \(\bar{x}\) is the mean annotation value.
The value can be tested using the R pacakge
spdep:x <- rnorm(100) m <- matrix(runif(100*100), nrow=100) w <- mat2listw(m) moran(v, w, 100, Szero(w)) # or moran.test(x, w)
Standardized Moran’s I [2] is calculated as:
\[Z_I = \frac{I - \mathbb{E}[I]}{\sqrt{\mathrm{Var}(I)}}\]where
\[\mathbb{E}[I] = -\frac{1}{n-1}\]and
\[\mathrm{Var}(I) = \frac{n^2 S_1 - n S_2 + 3 S_0^2} {(n-1)(n-2)(n-3) S_0^2} - \left( \frac{1}{n-1} \right)^2,\]with
\[S_0 = \sum_i\sum_j w_{ij},\]\[S_1 = \frac{1}{2} \sum_{ij} (w_{ij} + w_{ji})^2,\]and
\[S_2 = \sum_i \left( \sum_j w_{ij} + \sum_j w_{ji} \right)^2.\]References