mantispy.tl.effect_size

Contents

mantispy.tl.effect_size#

mantispy.tl.effect_size(adata, groupby='Metadata_Perturbation', reference='negcon', method='cohens_d', pvalues=True, min_obs=2, key_added='effect', copy=False)#

Per-feature effect size of each group against the reference.

Parameters:
  • adata (AnnData) – Object to score, at cell or profile resolution.

  • groupby (str (default: 'Metadata_Perturbation')) – Column defining the groups to score.

  • reference (str | None (default: 'negcon')) – Rows to compare against: "negcon", None for everything, or a boolean obs column. The reference group is also scored against itself as a calibration check; its effects should be near zero.

  • method (str (default: 'cohens_d')) – "cohens_d" is the difference in means over the pooled standard deviation. "robust_z" is the difference in medians in units of control MAD, which a few extreme cells cannot move.

  • pvalues (bool (default: True)) – Compute a Mann-Whitney p-value for each effect. At single-cell resolution nearly every feature is significant, so turn them off when ranking by effect.

  • min_obs (int (default: 2)) – Groups with fewer rows than this are left unscored as NaN.

  • key_added (str (default: 'effect')) – Name for the outputs.

  • copy (bool (default: False)) – Return a modified copy instead of mutating in place.

Return type:

AnnData | None

Returns:

None, or the modified copy. Writes varm[key_added], a (n_vars, n_groups) float32 array with columns in the order of uns["mantispy"][key_added + "_groups"], and uns["mantispy"][key_added], a tidy frame with group, feature, effect, pvalue (Mann-Whitney U, two-sided, NaN when pvalues=False) and qvalue (Benjamini-Hochberg over the whole table, since it is one family of tests).

Raises:

ValueErrormethod is not one of METHODS, or reference selects fewer than two rows.

Notes

The p-value tests whether the distributions differ, and its significance grows with the number of rows. The effect size measures by how much, and does not grow with the number of rows. At single-cell resolution nearly everything is significant, so rank by effect and use the q-value only to filter.