squidpy.gr.ripley

squidpy.gr.ripley(adata, cluster_key, mode='F', spatial_key='spatial', metric='euclidean', n_neigh=2, n_simulations=100, n_observations=1000, max_dist=None, n_steps=50, rng=None, copy=False, *, table_key=None)[source]

Calculate various Ripley’s statistics for point processes.

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.

According to the ‘mode’ argument, it calculates one of the following Ripley’s statistics: ‘F’, ‘G’ or ‘L’ statistics.

‘F’, ‘G’ are defined as:

\[F(t),G(t)=P( d_{i,j} \le t )\]

Where \(d_{i,j}\) represents:

  • distances to a random Spatial Poisson Point Process for ‘F’.

  • distances to any other point of the dataset for ‘G’.

‘L’ we first need to compute \(K(t)\), which is defined as:

\[K(t) = \frac{1}{\lambda} \sum_{i \ne j} \frac{I(d_{i,j}<t)}{n}\]

and then we apply a variance-stabilizing transformation:

\[L(t) = (\frac{K(t)}{\pi})^{1/2}\]
Parameters:
Return type:

dict[str, DataFrame | NDArray[Any]]

Returns:

If copy = True, returns a dict with following keys:

  • ’{mode}_stat’ - pandas.DataFrame containing the statistics of choice for the real observations.

  • ’sims_stat’ - pandas.DataFrame containing the statistics of choice for the simulations.

  • ’bins’ - numpy.ndarray containing the support.

  • ’pvalues’ - numpy.ndarray containing the p-values for the statistics of interest.

Otherwise, modifies the adata object with the following key:

Statistics and p-values are computed for each cluster anndata.AnnData.obs ['{cluster_key}'] separately.

References

For reference, check out Wikipedia or [Baddeley et al., 2015].