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, rng=None, use_raw=False, copy=False, n_jobs=None, backend='loky', show_progress_bar=True, *, table_key=None)[source]

Calculate Global Autocorrelation Statistic (Moran’s I or Geary’s C).

See [Rey and Anselin, 2010] for reference.

Changed in version 1.8.2: The analytic (normality-assumption) variance for Geary’s C was corrected; previously the Moran’s I variance was reused for mode = 'geary'. As a result, 'var_norm' and 'pval_norm' for Geary’s C differ from earlier versions. Permutation-based p-values ('pval_sim', 'pval_z_sim') are unaffected. See #1183.

Changed in version 1.8.4: Every permutation now uses an independent numpy.random.Generator spawned from a numpy.random.SeedSequence. Consequently the permutation-based results no longer depend on n_jobs / backend, but results obtained with a given seed differ from those produced by squidpy < 1.8.4. See #1232 and #1233.

Changed in version 1.8.4: seed / random_state were renamed to rng, which also accepts a numpy.random.Generator (SPEC 7). The old names still work but emit a FutureWarning.

Parameters:
Return type:

DataFrame | None

Returns:

If copy = True, returns a pandas.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: