vm.pp.mad_scale
Robustly center or scale a numeric vector or matrix.
Signature
def mad_scale(
x: numpy.ndarray | pandas.Series | pandas.DataFrame,
*,
axis: int = 0,
center: bool = True,
scale: bool = True,
constant: float = 1.4826,
na_rm: bool = True,
zero_mad: str = "zero",
) -> numpy.ndarray | pandas.Series | pandas.DataFrame: ...
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | `numpy.ndarray | pandas.Series | pandas.DataFrame` |
axis | int | 0 | Scale columns with 0 or rows with 1. Ignored for vectors. |
center | bool | True | Subtract the median. |
scale | bool | True | Divide by the MAD multiplied by constant. |
constant | float | 1.4826 | Positive MAD scaling factor. Use 1 for raw MAD. |
na_rm | bool | True | Ignore NaNs when estimating location and spread. |
zero_mad | str | 'zero' | Use zero (zero), return missing values (na), or raise (error) for a slice with zero MAD. |
Returns
numpy.ndarray, pandas.Series, or pandas.DataFrame
Scaled data in the input container type.
Raises
TypeError
If the input is not numeric or Boolean options have invalid types.
ValueError
If the axis or scale factor is invalid, values contain infinities, or a zero MAD is encountered with zero_mad='error'.
Notes
The default scaling factor (1.4826) converts raw MAD to the normal
consistency scale. Set constant=1 to use raw MAD. Missing values are
preserved in the result. This function does not modify its input.
See Also
Examples
import verymadpy as vm
scaled = vm.pp.mad_scale(adata.obs["total_counts"])