pylimma.remove_batch_effect
- pylimma.remove_batch_effect(x, batch=None, batch2=None, covariates=None, design=None, group=None, *, out_layer='batch_removed', uns_key='remove_batch_effect', layer=None, **lmfit_kwargs)[source]
Remove batch effects from a matrix of expression values.
Faithful port of R limma’s
removeBatchEffect(limma/R/removeBatchEffect.R). Fits a linear model against a combined design of experimental conditions and batch covariates, then subtracts the estimated batch-coefficient contribution from the expression matrix.- Parameters:
x (ndarray, EList, AnnData, or dict) – Expression matrix (genes x samples) or wrapper.
batch (array-like, optional) – Factor of batch labels. Coded with sum-to-zero contrasts before entering the design.
batch2 (array-like, optional) – Second batch factor, treated the same way as
batch.covariates (ndarray, optional) – Quantitative covariates (samples x p). Mean-centred before entry.
design (ndarray, optional) – Design matrix for the experimental conditions to be preserved. If omitted and
groupis also omitted, a one-group design is assumed and a warning is emitted.group (array-like, optional) – If given and
designis omitted, setsdesign = one_hot(group).**lmfit_kwargs – Forwarded to
lm_fit(e.g.weights,method).out_layer (str)
uns_key (str)
layer (str | None)
- Return type:
Same class as input (matrix -> ndarray, EList -> EList, AnnData -> None).