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',))) –obscolumns 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, whichsc.pp.regress_outcannot do.Nonefits one model globally.key_added (
str|None(default:None)) – Write tolayers[key_added]instead of overwritingX.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:
- Raises:
KeyError – If any of
keysis not anobscolumn.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_firstremoved, so those rows would be corrected as the reference level and take every other row with them.