netneurotools.spatial.local_morans_i
- netneurotools.spatial.local_morans_i(annot, weight, use_sampvar=True)[source]
Calculate local 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_sampvar (bool, optional) – Whether to use sample variance (n - 1) in calculation. Default: True.
- Returns:
local_morans_i – Local Moran’s I values for the given annotations and weight matrix.
- Return type:
array, shape (n,)
Notes
Local Moran’s I is calculated as:
\[I_i = \frac{(x_i - \bar{x})}{\sum_{k=1}^n (x_k - \bar{x})^2/(n-1)} \sum_{j=1}^n w_{ij}(x_j - \bar{x})\]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) localmoran(x, mat2listw(m), mlvar=TRUE)
See also
netneurotools.spatial.spatial_stats.morans_i