Skip to contents

This function identifies outliers in a numeric vector using Median Absolute Deviation (MAD) method, with specialized handling for very small samples. Returns results in htest format for consistency with statistical tests.

Usage

mad.test(x, na.rm = TRUE)

Arguments

x

A numeric vector. Missing values (NA) are allowed and will be excluded from calculations.

na.rm

Logical. Should missing values be removed? Default is TRUE.

Value

An object of class "htest" containing:

statistic

The test statistic (MAD-based z-score of most extreme outlier)

parameter

Named vector with: n, median, mad, threshold

p.value

Approximate p-value based on outlier probability

method

Description of the method used

data.name

Name of the data vector

alternative

Character string describing the alternative hypothesis

outlier.indices

Indices of detected outliers (as additional element)

Details

For samples with n > 5, uses standard MAD method with threshold of 3. For very small samples (n <= 5), uses MAD with adjusted thresholds:

  • n = 3-4: threshold = 2.5

  • n = 5: threshold = 2.8

The test statistic is calculated as the maximum absolute deviation from median divided by adjusted MAD.

Examples

if (FALSE) { # \dontrun{
# Basic usage
x <- c(1, 2, 3, 100, 4, 5, 3)
mad.test(x)

# Small sample
x3 <- c(1, 2, 10)
mad.test(x3)
} # }