Distinguish additive and multiplicative time series decompositions and determine when log transformation aligns the two.
Compute centered and trailing moving averages via slider::slide_dbl() and account for phase lag and boundary truncation.
Fit and tune robust STL decompositions (feasts::STL) and distinguish fixed-period seasonality from irregular multi-year cycles.
1. Additive vs. Multiplicative Decomposition
A classical exploratory step decomposes a seasonal time series \(y_t\) into a slowly varying trend-cycle component \(T_t\), a repeating seasonal component \(S_t\), and an irregular remainder\(R_t\):
An additive structure is appropriate when the seasonal swing remains roughly constant in magnitude regardless of the series level. A multiplicative structure is appropriate when seasonal swings grow proportionally with the trend level. For strictly positive data (\(y_t > 0\)), taking natural logarithms turns a multiplicative model into an additive one:
\[
\ln y_t = \ln T_t + \ln S_t + \ln R_t.
\]
Seasonal decomposition is meaningful only when a series exhibits genuine calendar seasonality (such as quarterly beverage demand, monthly retail employment, or airline passengers). Never apply seasonal decomposition blindly to non-seasonal financial price series such as daily stocks: extracting a forced seasonal curve from a random walk produces spurious artifacts.
2. Moving Average Smoothing: Trailing vs. Centered
Moving averages estimate the smooth trend-cycle \(T_t\) by locally averaging nearby observations. For a window width \(k\):
A trailing (causal) \(k\)-MA averages only current and past values: \[\hat{T}_t^{\text{trail}} = \frac{1}{k} \sum_{j=0}^{k-1} y_{t-j}.\] Because every weight lies in the past, a trailing smoother introduces a phase lag of \((k-1)/2\) periods and drops the first \(k-1\) observations.
A centered odd-\(k\) MA (\(k = 2m + 1\)) balances observations symmetrically around \(t\): \[\hat{T}_t^{\text{cent}} = \frac{1}{2m + 1} \sum_{j=-m}^{m} y_{t+j}.\] Symmetric averaging eliminates phase lag at the cost of truncating \(m\) observations at each boundary. For even seasonal periods (such as \(m = 4\) quarters), applying a 2-MA to a 4-MA (\(2 \times 4\)-MA) restores exact symmetry while cancelling the seasonal cycle.
Let us compute a trailing 5-quarter MA and a centered 5-quarter MA on quarterly Australian beer production using slider::slide_dbl() with .complete = TRUE (ensuring exact window lengths and clean NA handling at the edges).
Figure 1: Quarterly Australian beer production overlaid with trailing (lagged) and centered 5-quarter moving averages.
3. STL Decomposition
Classical moving-average decomposition assumes a fixed seasonal shape and loses boundary values. STL (Seasonal and Trend decomposition using Loess) overcomes both limitations via iterative local weighted regressions (feasts::STL()). Three arguments control its behavior:
trend(window = ...): odd integer controlling the smoothness of \(T_t\) (larger values produce smoother trends).
season(window = ...): odd integer controlling how quickly the seasonal component \(S_t\) may evolve over time, or "periodic" to hold seasonality strictly constant across years.
robust = TRUE: applies iteratively reweighted robustness weights so isolated shocks or outliers are absorbed into the remainder \(R_t\) rather than distorting \(T_t\) or \(S_t\).
We apply robust STL to monthly U.S. retail trade employment from 1990 onward.
Figure 2: Robust STL decomposition of U.S. monthly retail trade employment (1990 onward), separating the macroeconomic trend, evolving holiday hiring spikes, and irregular shocks.
Notice the grey scale bars along the left edge of each panel: all bars represent the same vertical data magnitude, visually emphasizing that the trend accounts for the largest overall range while seasonal holiday surges remain a substantial, gradually evolving component.
4. Regular Seasonality vs. Multi-Year Cycles
Students often conflate seasonality with cycles. They differ structurally:
Seasonality has a fixed, known calendar period\(m\) (12 months, 4 quarters, 7 days) driven by weather, holidays, or institutional schedules.
Cycles are rises and falls with no fixed calendar period, typically spanning multiple years with asymmetric expansions and contractions (business cycles, predator-prey ecology).
Monthly airline passengers (AirPassengers) illustrate strict multiplicative seasonality (\(m = 12\) months, peaking every July/August), whereas Canadian lynx trappings (pelt$Lynx) exhibit an irregular ~9 to 11 year ecological cycle without calendar seasonality.
Figure 3: Strict 12-month calendar seasonality with growing amplitude in AirPassengers (left) contrasted with irregular ~10-year predator-prey cycles in Canadian lynx trappings (right).
Practice Exercises
Exercise 1: Tuning STL Seasonal Windows
On us_employment (Title == "Retail Trade", year(Month) >= 1990), fit two robust STL decompositions with trend(window = 21): one with season(window = "periodic") and one with season(window = 7). Compare the standard deviation of the remainder component and explain why they differ.
Solution
Allowing season(window = 7) lets the December holiday hiring spike adapt across decades, reducing the remainder standard deviation compared to forcing a strictly constant "periodic" seasonal pattern.
Comparison of STL remainder dispersion under periodic vs. adaptive seasonal windows.
.model
Remainder SD
Max |Remainder|
Adaptive
42.10
154.7
Periodic
45.92
183.4
Exercise 2: Log-Scale STL on AirPassengers
Apply robust STL (trend(window = 15) + season(window = 13)) to log(value) of as_tsibble(AirPassengers). Verify that the seasonal component has nearly uniform amplitude across time on the log scale and plot the decomposition.
Solution
Because raw AirPassengers exhibits multiplicative seasonal amplitude growth, taking log(value) stabilizes the seasonal swings so an additive STL decomposition yields clean, nearly constant seasonal fluctuations and a small homoscedastic remainder.
air_stl <-as_tsibble(AirPassengers) |>model(STL(log(value) ~trend(window =15) +season(window =13), robust =TRUE)) |>components()air_stl |>as_tibble() |>mutate(Half =ifelse(year(index) <=1954, "1949–1954", "1955–1960")) |>group_by(Half) |>summarise(`Seasonal SD (log)`=sd(season_year),`Remainder SD (log)`=sd(remainder) ) |>fmt_tbl(digits =4, caption ="Log-scale seasonal and remainder stability across early vs. late AirPassengers.")
Log-scale seasonal and remainder stability across early vs. late AirPassengers.
Figure 4: Robust STL decomposition of log(AirPassengers), showing stabilized seasonal amplitude on the log scale.
Key Takeaways
Use additive decomposition when seasonal swings have constant magnitude and log-scale (multiplicative) decomposition when seasonal amplitude scales proportionally with the level.
Centered moving averages eliminate the \((k-1)/2\) phase lag of trailing averages at the cost of boundary truncation; compute both cleanly with slider::slide_dbl(..., .complete = TRUE).
Robust STL (feasts::STL(..., robust = TRUE)) flexibly separates trend, evolving seasonality, and outliers without discarding edge points.
Never confuse fixed-period calendar seasonality with multi-year cycles, and never apply seasonal decomposition to non-seasonal stock price series.