mantispy.pp.regress_out

Contents

mantispy.pp.regress_out#

mantispy.pp.regress_out(adata, keys=('Metadata_CellCount',), by='Metadata_Plate', key_added=None, copy=False)#

Regress confounders out of every feature, within groups.

Parameters:
  • adata (AnnData) – Object to correct.

  • keys (Sequence[str] (default: ('Metadata_CellCount',))) – obs columns to regress out. Numeric columns enter directly; categorical ones are one-hot encoded with the first level dropped.

  • by (str | None (default: 'Metadata_Plate')) – Fit separately within each group of this column, usually the plate, which sc.pp.regress_out cannot do. None fits one model globally.

  • key_added (str | None (default: None)) – Write to layers[key_added] instead of overwriting X.

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

Returns:

the mean over the whole object for a numeric covariate, and the group’s own mean for a categorical one, which keeps the units of the data.

Return type:

AnnData | None

Raises:
  • KeyError – If any of keys is not an obs column.

  • ValueError – If a categorical covariate has missing values.

Notes

Missing and infinite values stay as they are, and a feature holding one is fitted on its finite rows. A group with no more rows than design columns is left uncorrected and logged.

A numeric covariate with a missing or infinite value is dropped from that group’s design and nothing is regressed out for it there, with a warning. A categorical covariate with a missing label is refused instead: the all-zero encoding of a missing category is also the encoding of the level drop_first removed, so those rows would be corrected as the reference level and take every other row with them.