atlas.tl.pearson_correlation

atlas.tl.pearson_correlation#

atlas.tl.pearson_correlation(mudata, key1, key2, seed=42, n_resamples=10000, confidence_level=0.95)#

Compute the Pearson correlation coefficient between two variables stored in mudata.obs.

Parameters:
  • mudata (MuData) – Multimodal annotated data object containing observations in .obs.

  • key1 (str) – Column name in mudata.obs for the first variable.

  • key2 (str) – Column name in mudata.obs for the second variable.

  • seed (int (default: 42)) – Random seed used for bootstrap resampling.

  • n_resamples (int (default: 10000)) – Number of resampling iterations for bootstrap estimation.

  • confidence_level (float (default: 0.95)) – Confidence level for the confidence interval.

Return type:

tuple

Returns:

-statistic (float)

Pearson correlation coefficient.

-pvalue (float)

Two-sided p-value associated with the correlation.

cituple[float, float] | None

Confidence interval as (low, high). Returns None if input contains NaNs.

Warns:
  • UserWarning – If input contains NaN values.

  • UserWarning – If the number of samples is smaller than 500 (bootstrap is used).

  • UserWarning – If the correlation is exactly ±1, the confidence interval may be undefined.

Raises:

KeyError – If either key1 and key2 are not in mudata.obs.

Notes

Pearson computation, pvalue are computed via scipy.stats.pearsonr().

Analytical confidence intervals are estimated via scipy.stats._result_classes.PearsonRResult.confidence_interval().

Bootstrap-based confidence intervals are used for small sample sizes to improve robustness.