netneurotools.spatial.gearys_c

netneurotools.spatial.gearys_c(annot, weight, use_numba=False)[source]

Calculate Geary’s C for spatial autocorrelation.

Parameters:
  • annot (array-like, shape (n,)) – Array of annotations to calculate Geary’s C 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).

Returns:

gearys_c – Geary’s C value for the given annotations and weight matrix.

Return type:

float

Notes

Geary’s C is calculated as:

\[C = \frac{(n-1)}{2\sum_{i=1}^n \sum_{j=1}^n w_{ij}} \frac{\sum_{i=1}^n \sum_{j=1}^n w_{ij}(x_i - x_j)^2} {\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)
geary(x, w, 100, 100-1, Szero(w))
# or
geary.test(x, w)