hampel_outlier: Rolling outlier detection using the Hampel identifier

View source: R/flags.R

hampel_outlierR Documentation

Rolling outlier detection using the Hampel identifier

Description

Detect outliers in a rolling window using the Hampel identifier.

Usage

hampel_outlier(x, k, threshold = 3.5)

Arguments

x

A vector of numbers.

k

Width of the rolling window (an odd integer).

threshold

Threshold for labeling outliers. For normally distributed data this is equivalent to standard deviations.

Details

The Hampel identifier uses the median absolute deviation (MAD) and a threshold to identify outliers based on their distance from the median \insertCitedavies_identification_1993atmoschem.process. This is a robust alternative to the commonly used thresholds mean +/-3sd to identify outliers \insertCiteleys_detecting_2013atmoschem.process.

Values are classified as outliers when

|X_i - med(X)| / MAD(X) > threshold

When the MAD is zero this equation is undefined. In this case the function returns FALSE.

Value

A vector of boolean values, TRUE if the value is an outlier.

References

\insertAllCited

Examples

# test a dataset with an outlier
x <- rnorm(20)
x[3] <- 10
hampel_outlier(x, 5)


ASRCsoft/atmoschem.datasets documentation built on Feb. 15, 2023, 9:26 a.m.