spac._ripley.ripley(adata: AnnData, cluster_key: str, mode: Literal['F', 'G', 'L'] = 'F', spatial_key: str = 'spatial', metric: str = 'euclidean', n_neigh: int = 2, n_simulations: int = 100, n_observations: int = 1000, max_dist: float | None = None, n_steps: int = 50, support: List[float] | None = None, seed: int | None = None, area: float | None = None, copy: bool = False, phenotypes: Tuple[str, str] | None = None) dict[str, pd.DataFrame | NDArrayA][source]

Calculate various Ripley’s statistics for point processes.

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

{rp.F.s!r}, {rp.G.s!r} 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 {rp.F.s!r}.

  • distances to any other point of the dataset for {rp.G.s!r}.

{rp.L.s!r} 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:
  • %(adata)s

  • %(cluster_key)s

  • mode – Which Ripley’s statistic to compute.

  • %(spatial_key)s

  • metric – Which metric to use for computing distances. For available metrics, check out sklearn.neighbors.DistanceMetric.

  • n_neigh – Number of neighbors to consider for the KNN graph.

  • n_simulations – How many simulations to run for computing p-values.

  • n_observations – How many observations to generate for the Spatial Poisson Point Process.

  • max_dist – Maximum distances for the support. If None, max_dist=\(\sqrt{{area \over 2}}\).

  • n_steps – Number of steps for the support.

  • support – list of bins (radiis) for the support. Overrides max_dist and n_steps.

  • phenotypes – For Ripley L, calculate the function for the cells of these two phenotypes.

  • %(seed)s – The seed for the random number generator.

  • %(area)s – Use passed value for area instead of the area of the convex hull.

  • %(copy)s

Return type:

%(ripley_stat_returns)s

References

For reference, check out Wikipedia or :cite:`Baddeley2015-lm`.