squidpy.gr.spatial_autocorr
- squidpy.gr.spatial_autocorr(adata, connectivity_key='spatial_connectivities', genes=None, mode='moran', transformation=True, n_perms=None, two_tailed=False, corr_method='fdr_bh', attr='X', layer=None, seed=None, use_raw=False, copy=False, n_jobs=None, backend='loky', show_progress_bar=True)[source]
Calculate Global Autocorrelation Statistic (Moran’s I or Geary’s C).
See [Rey and Anselin, 2010] for reference.
- Parameters:
adata (
AnnData
|SpatialData
) – Annotated data object.connectivity_key (
str
) – Key inanndata.AnnData.obsp
where spatial connectivities are stored. Default is:anndata.AnnData.obsp
['spatial_connectivities']
.genes (
Union
[str
,int
,Sequence
[str
],Sequence
[int
],None
]) –Depending on the
attr
:if
attr = 'X'
, it corresponds to genes stored inanndata.AnnData.var_names
. If None, it’s computedanndata.AnnData.var
['highly_variable']
, if present. Otherwise, it’s computed for all genes.if
attr = 'obs'
, it corresponds to a list of columns inanndata.AnnData.obs
. If None, use all numerical columns.if
attr = 'obsm'
, it corresponds to indices inanndata.AnnData.obsm
['{layer}']
. If None, all indices are used.
mode (
Literal
['moran'
,'geary'
]) –Mode of score calculation:
’moran’ - Moran’s I autocorrelation.
’geary’ - Geary’s C autocorrelation.
transformation (
bool
) – If True, weights inanndata.AnnData.obsp
['spatial_connectivities']
are row-normalized, advised for analytic p-value calculation.n_perms (
Optional
[int
]) – Number of permutations for the permutation test. If None, only p-values under normality assumption are computed.two_tailed (
bool
) – If True, p-values are two-tailed, otherwise they are one-tailed.corr_method (
str
|None
) – Correction method for multiple testing. Seestatsmodels.stats.multitest.multipletests()
for valid options.use_raw (
bool
) – Whether to accessanndata.AnnData.raw
. Only used whenattr = 'X'
.layer (
Optional
[str
]) – Depending onattr
: Layer inanndata.AnnData.layers
to use. If None, useanndata.AnnData.X
.attr (
Literal
['obs'
,'X'
,'obsm'
]) – Which attribute ofAnnData
to access. Seegenes
parameter for more information.copy (
bool
) – IfTrue
, return the result, otherwise save it to theadata
object.backend (
str
) – Parallelization backend to use. Seejoblib.Parallel
for available options.show_progress_bar (
bool
) – Whether to show the progress bar or not.
- Return type:
- Returns:
: If
copy = True
, returns apandas.DataFrame
with the following keys:’I’ or ‘C’ - Moran’s I or Geary’s C statistic.
’pval_norm’ - p-value under normality assumption.
’var_norm’ - variance of ‘score’ under normality assumption.
’{p_val}_{corr_method}’ - the corrected p-values if
corr_method != None
.
If
n_perms != None
, additionally returns the following columns:’pval_z_sim’ - p-value based on standard normal approximation from permutations.
’pval_sim’ - p-value based on permutations.
’var_sim’ - variance of ‘score’ from permutations.
Otherwise, modifies the
adata
with the following key:anndata.AnnData.uns
['moranI']
- the above mentioned dataframe, ifmode = 'moran'
.anndata.AnnData.uns
['gearyC']
- the above mentioned dataframe, ifmode = 'geary'
.