Skip to contents

Universal thresholding of Haar detail coefficients at \(\sigma\sqrt{2\log n}\), with sigma from the median absolute deviation of the finest level.

Usage

morie_discrete_wavelet_anomaly(
  x,
  threshold = NULL,
  levels = NULL,
  max_span = 8
)

Arguments

x

series.

threshold

explicit threshold; universal when NULL.

levels

decomposition levels.

max_span

widest region a firing coefficient may mark.

Value

list with anomaly, score, sigma, threshold, level_fired, per_level_count.

Details

The LEVEL at which a coefficient fires is the diagnostic, not just the fact that one did: a single-point spike fires at level 1 only, while a level shift fires at every coarse scale. level_fired records it, and max_span caps how wide a region a coarse coefficient is allowed to mark, so one level-6 coefficient cannot paint 64 points as anomalous.

The Haar basis localises abrupt changes and is blind to slow drift, which produces no large coefficient at any scale.

The max_span cap has a consequence worth knowing: a sustained LEVEL SHIFT fires large coefficients at coarse scales, but those are not allowed to mark their whole span, so the shift appears in per_level_count without appearing in anomaly. The cap buys sharp localisation of spikes at that price; raise max_span to mark shifts as well.

References

Donoho, D. L. and Johnstone, I. M. (1994). Ideal spatial adaptation by wavelet shrinkage. Biometrika, 81(3), 425-455.

Examples

set.seed(1)
y <- rnorm(128); y[40] <- 9
which(morie_discrete_wavelet_anomaly(y)$anomaly)
#> [1] 33 34 35 36 37 38 39 40