Detects outliers in numeric data using the Median Absolute Deviation (MAD) method. This robust method is less sensitive to extreme values than standard deviation and works well for non-normally distributed data.
detect_outliers_mad(data, k = 3, take_log = FALSE)
A list containing:
Logical vector indicating outliers
List containing:
median: Median of data
mad: Median absolute deviation
n_outliers: Number of outliers detected
Numeric vector of values to analyze
Numeric threshold for outlier detection (default: 3). Points more than k MADs from median are considered outliers.
Logical. Whether to log transform data before (and only for) outlier detection (default: FALSE)
The function:
Calculates median and MAD of the data
Uses scaled MAD (constant = 1.4826) for normal distribution consistency
Identifies points > k MADs from median as outliers
Returns both outlier mask and summary statistics
MAD scaling constant 1.4826 is calculated as 1/Phi^(-1)(3/4), where Phi is the standard normal CDF. This makes MAD consistent with standard deviation for normal distributions.