Statistics Glossary → STL Seasonal Decomposition
STL Seasonal Decompositionanalysis
A method that splits a time series into its long-term direction (trend), a regularly repeating seasonal pattern and the remaining irregular fluctuation (remainder).
Concept
Series such as monthly sales or temperature carry several movements at once: a rise or fall lasting years, a wave repeating in the same months every year, and irregular ups and downs that neither explains. When these movements are tangled together, the raw plot cannot answer 'are sales really growing, or has summer simply arrived?'. STL separates these components so that each can be examined on its own.
The method assumes an additive structure: observed = trend + seasonal + remainder. The seasonal component is found by smoothing each seasonal position (e.g. all the Januaries) locally with LOESS, and the trend by smoothing the deseasonalised series; the two steps are repeated so that each corrects the other. How dominant the components are is summarised by strength measures; for instance, seasonal strength F_S = 1 − Var(remainder) / Var(seasonal + remainder), with values near 1 meaning strong seasonality.
STL is descriptive; it does not test the trend or the season for significance. The results are sensitive to the choice of period and windows. If the amplitude of the seasonal wave grows with the level of the series (a multiplicative structure), the decomposition should be done after a log or Box-Cox transformation.
When to use it
- To see a series' trend and seasonal structure, to obtain a seasonally adjusted series, or to compute the typical seasonal effect of each month.
- When hourly or daily data contain more than one seasonal cycle, such as daily and weekly, use MSTL.
- If the question is whether the trend is statistically significant, use the Mann-Kendall test; if the components are to be estimated within a probability model and used for forecasting, an unobserved components model or Holt-Winters is preferred.
An everyday example
Think of ten years of monthly ice-cream sales at a supermarket in a seaside town. Sales soar every summer and drop every winter, while the town's growing population makes them creep up from year to year. STL splits this series into three: the trend component shows the slow ten-year rise, the seasonal component shows, for example, that July runs 400 boxes above the average and January 300 below, and the remainder shows one-off departures such as an unexpected heatwave.
Parameters in MerQur
Period (period; 0 = automatic)
Concept: The period is the number of observations after which the seasonal cycle repeats. The correct period makes observations in the same seasonal position (e.g. all the Julys) be considered together; with the wrong period the seasonal pattern leaks into the remainder.
Everyday example: For monthly ice-cream sales the period is 12: each July is compared with the previous July. If 6 is entered by mistake, summer and winter are treated as the same 'season' and the summer peak shows up as large departures in the remainder.
What it does: Length m of the seasonal cycle. With 0, from the date frequency: daily 7, weekly 52, monthly 12, quarterly 4, hourly 24, otherwise 12.
Effect on the result: Seasonal subseries, the trend window and all components.
On the validation data: nottem: automatic and 12 are the same; with a wrong period m = 6, F_S drops to 0.0904 and the residual SD rises from 1.70 to 4.80.
Robust
Concept: The robust option repeatedly gives low weight to observations with large remainders. A few outliers therefore do not pull the trend and seasonal components towards themselves; instead they stand out clearly in the remainder.
Everyday example: Suppose the supermarket was closed for refurbishment one August and sales were close to zero. With the robust option on, that month does not drag down the August seasonal effect; it simply remains as a large negative departure in the remainder.
What it does: An outer loop that downweights outliers with bisquare weights (Cleveland et al. 1990).
Effect on the result: The trend, seasonal and remainder components; extreme observations get low weight.
On the validation data: nottem: against the default F_S 0.9582, robust F_S is 0.9456; F_T falls below 0.2347.
Seasonal window (s.window; 0 = default 7) and Periodic
Concept: The seasonal window sets how much the seasonal pattern may change from year to year: a small window allows an evolving season, a large one produces a steadier pattern. With the periodic option exactly the same seasonal pattern is used every year.
Everyday example: If tourists have recently started visiting the town in September too, the seasonal effect of September sales grows over the years; a small seasonal window captures this change. The periodic option instead gives the same September effect to all ten years.
What it does: The LOESS window that smooths the seasonal subseries; as it grows, the seasonal pattern changes less from year to year. In the periodic option the same seasonal is used in every cycle (subseries mean).
Effect on the result: The seasonal component, F_S and the remainder.
On the validation data: nottem F_S: default 0.9582, 0.9512 for s.window 13, periodic 0.9438.
Trend window (t.window; 0 = default nextodd(1.5m/(1 - 1.5/s.window)))
Concept: The trend window sets how flexible the trend is: a wide window gives a smooth, slowly changing trend, while a narrow one gives a wiggly trend that also follows shorter waves. The trend strength (F_T) changes with this choice.
Everyday example: With a wide trend window, the trend of ice-cream sales is a smooth rising line over the ten years. With a narrow window, the dip in an economically difficult year also shows up in the trend.
What it does: The LOESS window that smooths the trend.
Effect on the result: The smoothness of the trend component and F_T.
On the validation data: nottem: default 23; a request of 50 becomes 51 (F_T 0.1009, a smoother trend); a request of 9 is raised to period + 1 (13) and stated in the note (F_T 0.3408).
Transform / λ (no transform (additive) / log (multiplicative) / Box-Cox (λ Guerrero) / Box-Cox (manual λ))
Concept: STL works additively; if the amplitude of the seasonal wave grows with the level of the series, a log transformation turns the multiplicative structure into an additive one. The Box-Cox transformation is a family that includes the log (λ = 0), with λ chosen so that the seasonal amplitude no longer depends on the level.
Everyday example: If sales double over ten years and the summer-winter gap doubles too, the seasonal effect is constant as a percentage rather than in boxes. Decomposing after a log transformation shows, for instance, that July runs about 40% above the average every year.
What it does: For a series whose amplitude grows with the level, performs the decomposition on the log (multiplicative) or Box-Cox scale; λ is chosen manually or by the Guerrero (1993) method. The λ box is used only when "manual λ" is selected.
Effect on the result: The scale of the components and F_S.
On the validation data: AirPassengers: log F_S 0.976; Guerrero λ = -0.29472; λ = 0.5: F_S 0.982; λ = -0.3: 0.972.
MSTL periods
Concept: MSTL estimates a separate seasonal component for each period when the series carries more than one seasonal cycle at the same time.
Everyday example: The supermarket's daily ice-cream sales have both a weekly cycle (high at weekends) and a yearly cycle (high in summer). Entering periods 7 and 365 lets MSTL show these two patterns separately.
What it does: Multiple seasonality (MSTL decomposition).
Effect on the result: A separate seasonal component for each period.
On the validation data: taylor "48, 336": F_S(48) = 0.9959, F_S(336) = 0.9877. nottem "12" single period: F_S 0.9534.
Additional output: Seasonal index, Residual diagnostics, Save
Concept: The seasonal index is the average seasonal effect of each seasonal position; the seasonally adjusted series is obtained by subtracting the seasonal component from the observed values. The remainder diagnostics test whether any autocorrelation or clear departure from normality is left in the remainder.
Everyday example: The seasonal index tells the store manager 'in January we normally sell 300 boxes below the average'. In the seasonally adjusted series one can see directly whether this January went well or badly for the time of year.
What it does: The seasonal index is the mean seasonal component per cycle position and the seasonally adjusted series. Residual diagnostics include the Ljung-Box (lag min(2m, n/5)), Shapiro-Wilk and Jarque-Bera tests. Save adds the STL_trend, STL_seasonal, STL_resid and STL_sa columns.
Effect on the result: Only additional output.
On the validation data: nottem: January -9.30, February -9.80; Ljung-Box (lag 24) Q = 163.23 (p < .001), Shapiro-Wilk W = 0.9944 (p = 0.52), Jarque-Bera 0.857 (p = 0.65).
Example on real data
Data: Nottingham monthly mean temperature 1920-1939, R datasets nottem
Variables: date date (monthly), value temp (temperature in Fahrenheit)
- Question: How does the 1920-1939 monthly mean temperature series of Nottingham (n = 240) decompose into long-term trend, regular seasonal pattern and random fluctuation components?
- Method: STL (seasonal-trend decomposition by LOESS), period 12, seasonal window 7, trend window 23; additive model: observed = trend + seasonal + remainder.
- Result: The seasonal component dominates: seasonal amplitude (SD) 8.3712, remainder SD 1.7413; the seasonal effect is -7.93 in January 1920 and +12.31 degrees in July 1920 (Fahrenheit).
- Component strength: Seasonal strength F_S = 0.9582 (≥ 0.64, strong seasonality); trend strength F_T = 0.2347 (weak trend). The trend mean is 49.03 and the trend SD only 0.78: there is no marked warming or cooling over twenty years.
- Limitation: The decomposition is descriptive and contains no test; the result is sensitive to the window choices (e.g. F_S changes with a periodic seasonal), and the robust option can be tried for outlying months.
- APA: The STL decomposition (period = 12, s.window = 7) showed strong seasonality (F_S = .96) and a weak trend (F_T = .23).
Related concepts
Seasonality and seasonal periodSmoothing parameter (λ, span)Box-Cox transformationM-estimator (Huber, Tukey biweight)Jarque-Bera testResidual plots and residual diagnosticsLjung-Box (portmanteau) testOutlier
The numbers in the examples are MerQur's output on independent, publicly available validation data; see the MerQur Technical Note for details.