Skip to content
AI360XpertBeta

Time Series Decomposition

A sales curve is trend plus repeating season plus noise, and each part is easier to forecast than the messy whole.

Four quarters of sales split into a rising trend, a repeating seasonal swing and leftover noise that add back to the observed values
Four quarters of sales split into a rising trend, a repeating seasonal swing and leftover noise that add back to the observed values

Why Does This Exist?

Plot monthly airline passengers over a decade and you get one jagged line climbing up and to the right, with a spike every summer. Hand that raw line to a forecaster and it struggles, because two different rhythms are tangled together: slow growth in flying, and a short repeating holiday surge. A model that tries to learn both at once usually learns neither well.

Decomposition untangles them before any forecasting starts. It splits each observation into a slow trend, a repeating seasonality, and a leftover residual, so each part can be modelled on its own terms. It is almost always the first thing you do with time-stamped data.

This page covers the two classical models, how STL pulls the parts out, and a four-quarter example you can check by hand. When you are ready to forecast, ARIMA models the parts with autocorrelation, exponential smoothing leans on weighted averages, and forecast evaluation keeps score.

Think of It Like This

Harbour water level

Stand at a harbour wall and watch the water height each noon. Three things move it. The sea itself creeps up year by year, which is the trend. The tides lift and drop it twice a day on a strict timetable, which is the seasonality. And the wind piles up chop that nobody scheduled, which is the residual.

A tide table works because someone separated those three first. Predict the creep, look up the tide, and admit the chop is chop.

Where it stops: real tides swell bigger in deep water, so the seasonal swing grows with the level. The basic additive split assumes fixed-size swings, and that is exactly when you switch to the multiplicative model below.

How It Actually Works

Every observation YtY_t at time tt is a combination of three pieces you cannot see directly: trend TtT_t, seasonality StS_t and residual RtR_t. Which combination depends on whether the seasonal swings grow with the level.

Additive or multiplicative

Use the additive model when the seasonal swings stay about the same size as the series grows:

Yt=Tt+St+RtY_t = T_t + S_t + R_t

Use the multiplicative model when the swings grow with the trend, like holiday sales that spike higher every year as the company gets bigger:

Yt=Tt×St×RtY_t = T_t \times S_t \times R_t

One practical escape: taking logs turns products into sums, so log⁡Yt=log⁡Tt+log⁡St+log⁡Rt\log Y_t = \log T_t + \log S_t + \log R_t. Fit the additive machinery to the logs, then exponentiate back. The snippet under Code checks that this round trip is exact.

STL (seasonal and trend decomposition using Loess) extracts the parts in a loop. It smooths the raw series to find the slow trend, subtracts it, averages across periods (all Januaries together, all Februaries together) to find the pure seasonal shape, and calls whatever remains the residual. Repeat until the pieces stop moving.

Worked example

Four quarters of sales, observed: Y=[12,9,14,11]Y = [12, 9, 14, 11]. Suppose the trend is T=[10,11,12,13]T = [10, 11, 12, 13], rising one unit a quarter, and the seasonal pattern repeats every two quarters: S=[+2,−2,+2,−2]S = [+2, -2, +2, -2], a holiday bump then a quiet quarter. Add them:

10+2=12,11−2=9,12+2=14,13−2=1110 + 2 = 12, \quad 11 - 2 = 9, \quad 12 + 2 = 14, \quad 13 - 2 = 11

That reproduces the observed series exactly, with residual R=[0,0,0,0]R = [0, 0, 0, 0]. The diagram draws these same four bars with the trend line running through them. Real data never lands this clean, which is the point of the residual: it measures how much of the series your trend plus season failed to explain.

Code

The point here is the log trick, not the formula. A multiplicative series becomes additive in log space, which is why one decomposition routine handles both models.

import math

trend = [100.0, 110.0, 120.0]season = [1.1, 0.9, 1.1]  # holiday lift, quiet stretch, holiday liftobserved = [t * s for t, s in zip(trend, season)]print([round(v, 2) for v in observed])  # -> [110.0, 99.0, 132.0]
logged = [math.log(v) for v in observed]split = [math.log(t) + math.log(s) for t, s in zip(trend, season)]print([round(v, 4) for v in logged])  # -> [4.7005, 4.5951, 4.8828]print([round(v, 4) for v in split])  # -> [4.7005, 4.5951, 4.8828]

Both routes agree to four decimals, so fitting the additive model to logged data is the same job as fitting the multiplicative model to the raw data.

Watch Out For

The residual still has a rhythm

You decompose, plot the residual, and see waves: up every December, down every January. That pattern sitting in the leftovers means the decomposition failed. Either the period is wrong (a weekly cycle hiding inside monthly data) or the swings grow while you fitted the additive model.

Check the residual against its own past with autocorrelation. If it correlates at some lag, that lag is the season you missed. If the swings widen over time, log the series and decompose again. Residuals should look like nothing, and anything else is a to-do list.

The trend wobbles at the edges

The first and last trend values swing oddly while the middle looks smooth. Smoothing needs neighbours on both sides, and the endpoints have neighbours on one side only, so the edge estimates are the weakest in the whole output.

Do not forecast from those edge values or report them as the current trend. STL dampens the problem but does not remove it. If the recent trend is the number you actually need, say so and use a method built for endpoints, like the smoothing models linked above.

The Quick Version

  • Decomposition splits each observation into trend, repeating seasonality and residual, and each part gets forecasted on its own.
  • Additive fits fixed-size seasonal swings, multiplicative fits swings that grow with the trend, and logs convert the second job into the first.
  • STL finds the trend by smoothing, the season by averaging across periods, and leaves the rest as residual.
  • Four quarters [12,9,14,11][12, 9, 14, 11] are trend [10,11,12,13][10, 11, 12, 13] plus season [+2,−2,+2,−2][+2, -2, +2, -2], exactly.
  • A residual with a rhythm means a missed season or the wrong model, and trend values at the series edges are the least trustworthy.