Learn R Programming

topolow (version 1.0.0)

detect_outliers_mad: Detect Outliers Using Median Absolute Deviation

Description

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.

Usage

detect_outliers_mad(data, k = 3, take_log = FALSE)

Value

A list containing:

outlier_mask

Logical vector indicating outliers

stats

List containing:

  • median: Median of data

  • mad: Median absolute deviation

  • n_outliers: Number of outliers detected

Arguments

data

Numeric vector of values to analyze

k

Numeric threshold for outlier detection (default: 3). Points more than k MADs from median are considered outliers.

take_log

Logical. Whether to log transform data before (and only for) outlier detection (default: FALSE)

Details

The function:

  1. Calculates median and MAD of the data

  2. Uses scaled MAD (constant = 1.4826) for normal distribution consistency

  3. Identifies points > k MADs from median as outliers

  4. 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.