Standardizes a numeric vector using robust statistics: median and
median absolute deviation (MAD). This method is less sensitive to outliers
compared to Z-score standardization.
Usage
norm_robust(x, na.rm = TRUE, constant = 1.4826)
Value
A numeric vector.
If MAD is 0 (e.g., more than 50
returns a centered vector (x - median) and issues a warning.
Arguments
x
A numeric vector.
na.rm
Logical. Should NA values be removed? Default is TRUE.
constant
A scale factor for MAD calculation. Default is 1.4826,
which ensures consistency with the standard deviation for normal distributions.
# Data with an outlierx <- c(1, 2, 3, 4, 100)
# Z-score is heavily affected by the outliernorm_zscore(x)
# Robust scaler handles it betternorm_robust(x)