Expand description
Seasonal-trend decomposition of a univariate series by Loess (STL).
A series y with a known period is split additively into a trend, a
seasonal component and a remainder, y = trend + seasonal + residual, by
the procedure of Cleveland, Cleveland, McRae & Terpenning (1990). The
period is an input — crate::seasonality::estimate_period estimates it
when it is not known.
§Algorithm
An inner loop refines the two components, starting from a zero trend:
- Detrend:
y − trend. - Cycle-subseries smoothing: the values at each position of the cycle
(every
period-th value) are smoothed by Loess with spanseasonal, and each subseries is extended one cycle before and after by Loess extrapolation. - Low-pass filter of that extended series: moving averages of length
period,periodand 3, then Loess with spanlow_pass. - Seasonal = step 2 − step 3 (the low-pass removes what of the trend leaked into the subseries).
- Trend = Loess with span
trendofy − seasonal.
The outer loop (only when robust) gives each point a robustness
weight from its remainder — the bisquare (1 − (r/h)²)² with
h = 6 · median|r| — and runs the inner loop again with every Loess fit
weighted by it, so that outliers go to the remainder instead of bending
the trend and seasonal components.
Each Loess fit is a local polynomial of degree 0 or 1 with tricube
weights over the span nearest points. This is the original Fortran
implementation (netlib stl), which statsmodels’ STL also follows, with
its defaults: degree 1 everywhere, seasonal = 7, trend the smallest
odd integer at least 1.5 · period / (1 − 1.5 / seasonal), low_pass the
smallest odd integer above period, and 5 inner / 0 outer iterations
(2 / 15 when robust).
§Strength of trend and seasonality
The result also reports F_T = max(0, 1 − Var(R)/Var(T + R)) and
F_S = max(0, 1 − Var(R)/Var(S + R)) (Wang, Smith & Hyndman 2006): near 1
when the component explains most of what the remainder does not, near 0
when it is indistinguishable from noise.
§Complexity
O(iterations · n · span) for spans seasonal, trend and low_pass.
§References
- Cleveland, R. B., Cleveland, W. S., McRae, J. E. & Terpenning, I. (1990). “STL: A seasonal-trend decomposition procedure based on Loess.” Journal of Official Statistics, 6(1), 3–73.
- Wang, X., Smith, K. & Hyndman, R. J. (2006). “Characteristic-based clustering for time series data.” Data Mining and Knowledge Discovery, 13(3), 335–364.
Structs§
- Stl
- STL decomposition with a builder for its options.
- StlResult
- An STL decomposition:
data[i] = trend[i] + seasonal[i] + residual[i].
Enums§
- StlError
- Why a decomposition was refused.
Constants§
- DEFAULT_
SEASONAL - Default span of the seasonal smoother (statsmodels’
seasonal=7).