detect_anomalies: Flag unusual points in a series

View source: R/diagnostics.R

detect_anomaliesR Documentation

Flag unusual points in a series

Description

A statistical check on the values themselves – distinct from the Holidays tab's consistency check (calendar-vs-declared-holiday mismatch). Uses the STL remainder when decompose_series() finds one (isolates unusual points from normal trend/seasonal movement, which a raw-value check can't); falls back to deviation from a running median when no seasonal decomposition applies (short series, yearly aggregation, etc.), so it still works on every series shape.

Usage

detect_anomalies(
  df,
  date_agg = "day",
  method = c("iqr", "zscore"),
  threshold = 1.5
)

Arguments

df

A tibble with ds/y columns.

date_agg

Aggregation frequency: one of "hour", "day", "week", "month", "quarter", "year".

method

"iqr" (the default) flags points outside threshold * IQR from the quartiles; "zscore" flags points more than threshold standard deviations from the mean.

threshold

Numeric sensitivity threshold. Default 1.5.

Value

A tibble with columns ds, y, score (the value the threshold was applied to), and is_anomaly (logical).

Examples

df <- tibble::tibble(ds = as.Date("2024-01-01") + 0:29, y = c(rep(10, 29), 100))
detect_anomalies(df, date_agg = "day", method = "iqr")

forecastsuite documentation built on Oct. 18, 2026, 5:08 p.m.