Skip to contents

A centred rolling median and MAD; the score is the robust z-score \(|y - med| / (1.4826\,MAD)\). Using the median rather than the mean is what keeps trend and seasonality from firing the detector.

Usage

morie_joseph_ts_outlier_detection(y, W = 10, threshold = 3.5)

Arguments

y

numeric series.

W

half-window; the full window is 2 * W + 1.

threshold

robust z-score above which a point is flagged.

Value

list with outlier, score, rolling_median, rolling_mad.

Details

The documented failure: a RUN of consecutive outliers longer than half the window becomes the local median itself and is declared normal. The window has to be wider than the longest run one expects to catch.

References

Iglewicz, B. and Hoaglin, D. C. (1993). How to Detect and Handle Outliers. ASQC Quality Press. (the 1.4826 MAD scaling and the 3.5 default)

Examples

y <- sin(seq(0, 6, length.out = 100))
y[50] <- 12
which(morie_joseph_ts_outlier_detection(y)$outlier)
#> [1] 50