Detect anomalies in time series using robust methods
anomaly.RdApplies anomaly detection to a ts object using either direct or decomposition-based methods.
Internally uses a customized version of anomalize logic with robust thresholding.
Arguments
- ts
A
tsobject. Input time series data.- max.anom
An integer (default: 100). Maximum number of anomalies allowed.
- scale
A numeric (default: 1.5). Controls the IQR scaling factor. Corresponds to standard 1.5×IQR rule. Internally converted to
alpha = 0.15 / scalefor compatibility withanomalize2().- method
A character. Outlier detection method passed to
anomalize2. One of"iqr"or"gesd".- decomp
A character or
NULL. Optional decomposition method for time series. One of"stl","twitter", etc., orNULLfor no decomposition. When specified, decomposes the time series using anomalize'stime_decompose().- tzero
A numeric (default: 0). Ignored. Included only for compatibility with other pipeline functions.
Value
A tibble with the original time series and added columns:
observedOriginal input values.
<observed>_l1,<observed>_l2Lower and upper bounds for anomaly detection.
anomalyAnomaly flag:
1for anomaly,0otherwise.- (Optional)
Additional decomposition columns:
trend,season,remainderifdecompis used.
Details
This function builds on anomalize by replacing the default anomaly detection with
customized functions iqr2 and gesd2, which return binary anomaly indicators (0 or 1).
Pipe operators are not used. The scale parameter is internally translated into a significance level
using the formula: alpha = 0.15 / scale.
If decomp is specified, the function decomposes the time series into trend, seasonal, and remainder components,
estimates the trend period automatically via ACF using decomp_freq_trend, and applies anomaly detection
to the remainder component only. The final result is then recomposed using time_recompose().