vm.pp.flag_mad_outliers
Flag observations outside fitted median absolute deviation thresholds.
Signature
def flag_mad_outliers(
data: anndata.AnnData | pandas.DataFrame,
*,
metrics: collections.abc.Mapping[str, str | collections.abc.Mapping[str, str | float]]
| collections.abc.Sequence[str]
| None = None,
n_mads: float | None = None,
transform: str | collections.abc.Mapping[str, str] | None = None,
min_n: int = 5,
zero_mad: str = "na",
overwrite: bool = False,
copy: bool = False,
batch_key: str | None = None,
mad_scale: str = "scaled",
key_added: str | None = None,
) -> anndata.AnnData | pandas.DataFrame | None: ...
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
data | `anndata.AnnData | pandas.DataFrame` | required |
metrics | `collections.abc.Mapping[str, str | collections.abc.Mapping[str, str | float]] |
n_mads | `float | None` | None |
transform | `str | collections.abc.Mapping[str, str] | None` |
min_n | int | 5 | Minimum number of finite values required per metric and batch. |
zero_mad | str | 'na' | Use missing flags (na), use the median as the threshold (zero), or raise an error (error) when the fitted MAD is zero. |
overwrite | bool | False | Allow replacing output columns and metadata for this run. |
copy | bool | False | Return a modified AnnData copy. DataFrames always return a copy. |
batch_key | `str | None` | None |
mad_scale | str | 'scaled' | Use scaled (1.4826 times raw MAD) or raw MAD. |
key_added | `str | None` | None |
Returns
AnnData, DataFrame, or None
With copy=True, return an annotated copy. Otherwise, annotate AnnData in place and return None; DataFrame input always returns a copy.
Raises
TypeError
If the input, metric values, or Boolean options have invalid types.
ValueError
If a setting is invalid or a transformation is outside its domain.
KeyError
If a required metric or batch column is missing.
Notes
AnnData flags are written to .obs and fitted settings and thresholds to
.uns['verymad']. DataFrame metadata is stored in .attrs. Missing
metric values and observations that cannot be classified remain undefined.
The default policy requires total_counts and n_genes_by_counts;
absent pct_counts_mt is omitted with a warning. Supplying metrics
replaces the default metric set.
See Also
Examples
import verymadpy as vm
vm.pp.flag_mad_outliers(adata, batch_key="sample_id")