decompose_series: Seasonal decomposition of a series

View source: R/diagnostics.R

decompose_seriesR Documentation

Seasonal decomposition of a series

Description

Surfaces the STL trend/seasonal/remainder split that analyze_series() already computes internally to drive the recommendation heuristic, as a tidy tibble a caller can plot directly.

Usage

decompose_series(df, date_agg = "day", robust = FALSE)

Arguments

df

A tibble with ds/y columns.

date_agg

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

robust

Logical; use robust (outlier-downweighted) STL – stats::stl(..., robust = TRUE) – instead of ordinary STL, so a handful of spikes/dips don't skew the trend/seasonal split. Default FALSE.

Value

A tibble with columns ds, observed, trend, seasonal, remainder, or NULL (not an error) when no candidate frequency has enough cycles of data, or date_agg has no seasonal candidates at all (e.g. "year").

Examples

n <- 60
df <- tibble::tibble(ds = as.Date("2024-01-01") + 0:(n - 1),
                      y = 100 + 10 * sin(2 * pi * seq_len(n) / 7) + rnorm(n))
decompose_series(df, date_agg = "day")

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