scanpy.metrics.gearys_c#
- scanpy.metrics.gearys_c(adata_or_graph, /, vals=None, *, use_graph=None, layer=None, obsm=None, obsp=None, use_raw=False)[source]#
Calculate Geary’s C.
Specifically as used by VISION.
Geary’s C is a measure of autocorrelation for some measure on a graph. This can be to whether measures are correlated between neighboring cells. Lower values indicate greater correlation.
\[C = \frac{ (N - 1)\sum_{i,j} w_{i,j} (x_i - x_j)^2 }{ 2W \sum_i (x_i - \bar{x})^2 }\]- Parameters:
- adata_or_graph
AnnData|csr_matrix AnnData object containing a graph (see
use_graph) or the graph itself. See the examples for more info.- vals
ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]] |spmatrix|Array|DataFrame|Series|None(default:None) Values to calculate Geary’s C for. If this is two dimensional, should be of shape
(n_features, n_cells). Otherwise should be of shape(n_cells,). This matrix can be selected from elements of the anndata object by using key word arguments:layer,obsm,obsp, oruse_raw.- use_graph
str|None(default:None) Key to use for graph in anndata object. If not provided, default neighbors connectivities will be used instead.
- layer
str|None(default:None) Key for
adata.layersto choosevals.- obsm
str|None(default:None) Key for
adata.obsmto choosevals.- obsp
str|None(default:None) Key for
adata.obspto choosevals.- use_raw
bool(default:False) Whether to use
adata.raw.Xforvals.
- adata_or_graph
- Return type:
- Returns:
If vals is two dimensional, returns a 1 dimensional ndarray array. Returns a scalar if
valsis 1d.
Examples
Calculate Geary’s C for each components of a dimensionality reduction:
import scanpy as sc, numpy as np pbmc = sc.datasets.pbmc68k_processed() pc_c = sc.metrics.gearys_c(pbmc, obsm="X_pca")
It’s equivalent to call the function directly on the underlying arrays:
alt = sc.metrics.gearys_c(pbmc.obsp["connectivities"], pbmc.obsm["X_pca"].T) np.testing.assert_array_equal(pc_c, alt)