squidpy.gr.ripley_k(adata, cluster_key, spatial_key='spatial', mode='ripley', support=100, copy=False)[source]

Calculate Ripley’s K statistics for each cluster in the tissue coordinates.

  • adata (AnnData) – Annotated data object.

  • cluster_key (str) – Key in anndata.AnnData.obs where clustering is stored.

  • spatial_key (str) – Key in anndata.AnnData.obsm where spatial coordinates are stored.

  • mode (str) – Keyword which indicates the method for edge effects correction. See astropy.stats.RipleysKEstimator for valid options.

  • support (int) – Number of points where Ripley’s K is evaluated between a fixed radii with \(min=0\), \(max=\sqrt{area \over 2}\).

  • copy (bool) – If True, return the result, otherwise save it to the adata object.

Return type



If copy = True, returns a pandas.DataFrame with the following keys:

  • ’ripley_k’ - the Ripley’s K statistic.

  • ’distance’ - set of distances where the estimator was evaluated.

Otherwise, modifies the adata with the following key: