Search

Search papers and lessons

Time Series Decomposition

Level 2 · 11 min read

Time series decomposition splits a series into a slow trend, a repeating seasonal pattern and a remainder, so each part can be read or removed on its own.

On this page

  • Colour = topic mix
  • Probability
  • Discrete math
  • Calculus
  • Linear algebra
  • Stochastic processes
  • Classical models
  • ReadReady to readNot yet

TL;DR

A time series is often a mix of a slow level that drifts, a pattern that repeats every season, and whatever is left over. Time series decomposition estimates each part separately, so the series can be read as trend plus season plus remainder. The most common version is additive, yt=Tt+St+Rty_t = T_t + S_t + R_t. It is a descriptive tool: it shows what is going on, and it is the usual first step before seasonal adjustment or forecasting.

Builds on: Stochastic Process, Linear Regression · Leads to: seasonal adjustment and forecasting of each component

Where it's used

Seasonal adjustment of official statistics. Retail sales rise every December for reasons that have nothing to do with the economy's direction. Statistics offices decompose the series, remove the seasonal part, and publish the adjusted figure, so that a real change is not hidden or invented by the calendar.

Electricity and energy demand. A city's daily demand has a weekly cycle, with weekdays busier than weekends, and a slow trend that follows growth or decline. Decomposition separates the weekly pattern from the trend, and the remainder shows unusual days such as public holidays or a heatwave.

Website and app traffic. A product team sees daily visits with a long upward trend and a strong weekly rhythm. Decomposing the series lets them judge whether a launch lifted the trend or just landed on a busy weekday.

How it works

Here is one tiny instance traced from start to finish. The series is quarterly, so the season repeats every 4 steps. It was built from a trend 10+t10 + t and a seasonal pattern (+2,0,−2,0)(+2, 0, -2, 0), with no noise. Over eight quarters it reads 13, 12, 11, 14, 17, 16, 15, 18.

  1. Start with the series. The values for t=1t = 1 to 88 are 13, 12, 11, 14, 17, 16, 15 and 18. Check: there are eight values, and the pattern goes up and down in a four-step rhythm.
  2. Estimate the trend with a centred moving average. For a quarterly series, average each point with its neighbours, giving the two ends of the window half weight: Tt=14(12yt−2+yt−1+yt+yt+1+12yt+2)T_t = \tfrac{1}{4}\left(\tfrac{1}{2}y_{t-2} + y_{t-1} + y_t + y_{t+1} + \tfrac{1}{2}y_{t+2}\right). This needs two points on each side, so t=3t = 3 to 66 get a trend, giving 13, 14, 15 and 16. Check: the trend rises by one each step, as the trend 10+t10 + t does.
  3. Remove the trend. Subtract it from the series at those four times: 11−13=−211 - 13 = -2, 14−14=014 - 14 = 0, 17−15=217 - 15 = 2, and 16−16=016 - 16 = 0. Check: these are the seasonal values with the trend gone.
  4. Average each season. Quarter 1 gives 22 (time 5), quarter 2 gives 00 (time 6), quarter 3 gives −2-2 (time 3), and quarter 4 gives 00 (time 4). Their sum is 0, so the pattern is already centred. Check: (2+0−2+0)=0(2 + 0 - 2 + 0) = 0.
  5. Compute the remainder. At each time, subtract the trend and the seasonal value: at t=3t = 3, 11−13−(−2)=011 - 13 - (-2) = 0. Check: every remainder here is 0, because the series had no noise.
  6. Read the result. The series is exactly trend plus season. The trend is the rising level, and the seasonal pattern is the four-step rhythm.

The diagram shows the four stages in order.

flowchart LR
  A[Series y] --> B[Trend by centred moving average]
  B --> C[Detrended values y minus trend]
  C --> D[Average by season, then centre]
  B --> E[Remainder y minus trend minus season]
  D --> E

The math

Definition: Additive decomposition

A series with period pp is written as

yt=Tt+St+Rt,y_t = T_t + S_t + R_t,

where TtT_t is the trend, StS_t is the seasonal component with St+p=StS_{t+p} = S_t, and RtR_t is the remainder. The seasonal values are centred so that they sum to zero over one period. For a series whose seasonal swings grow with its level, the multiplicative form yt=TtStRty_t = T_t S_t R_t fits better. Taking logarithms turns it into the additive form for log⁡yt\log y_t.

Step 1 in symbols: the trend

For an even period pp, the classical trend is a centred 2×p2 \times p moving average, with half weight on the two end points:

T^t=1p(12yt−p/2+yt−p/2+1+⋯+yt+p/2−1+12yt+p/2).\hat T_t = \frac{1}{p}\left(\tfrac{1}{2} y_{t - p/2} + y_{t - p/2 + 1} + \cdots + y_{t + p/2 - 1} + \tfrac{1}{2} y_{t + p/2}\right).

For p=4p = 4 this is the formula in the walkthrough. Because it needs p/2p/2 points on each side, the first and last p/2p/2 times have no trend estimate. A moving average is a simple smoothing device, and the Exponential Moving Average is a related one that weights recent points more.

Step 2 in symbols: the detrended series

Let dt=yt−T^td_t = y_t - \hat T_t at every time with a trend. In the walkthrough, d3=−2d_3 = -2, d4=0d_4 = 0, d5=2d_5 = 2 and d6=0d_6 = 0.

Step 3 in symbols: the seasonal component

Let s(t)s(t) be the season index of time tt, from 1 to pp. The raw seasonal value for season ii is the average of the detrended values in that season,

Sˉi=1ni∑t: s(t)=idt,\bar S_i = \frac{1}{n_i} \sum_{t:\, s(t) = i} d_t,

where nin_i is the number of such times. Averaging by season is the same as a regression of the detrended values on season indicators. Then centre the values, Si=Sˉi−1p∑j=1pSˉjS_i = \bar S_i - \frac{1}{p}\sum_{j=1}^{p} \bar S_j, so that they sum to zero. In the walkthrough each season has one value, so Sˉ=(2,0,−2,0)\bar S = (2, 0, -2, 0), which already sums to zero.

Step 4 in symbols: the remainder

The remainder at each time is Rt=yt−T^t−Ss(t)R_t = y_t - \hat T_t - S_{s(t)}. For t=3t = 3, R3=11−13−(−2)=0R_3 = 11 - 13 - (-2) = 0. In a real series the remainder carries the noise and any unusual events, and it is the part that should look structureless.

Worked examples

Example
1. Tiny: centring the seasonal values

Suppose the averaged seasonal values for a quarterly series are (1,3,−1,1)(1, 3, -1, 1).

  1. Their sum is 1+3−1+1=41 + 3 - 1 + 1 = 4.
  2. The centring shift is 4/4=14 / 4 = 1, the average of the four values.
  3. Subtract the shift from each value: (1−1,3−1,−1−1,1−1)=(0,2,−2,0)(1 - 1, 3 - 1, -1 - 1, 1 - 1) = (0, 2, -2, 0).
  4. Check: the new values sum to 0+2−2+0=00 + 2 - 2 + 0 = 0.
  5. Interpretation: the centring moves the overall level into the trend, so the seasonal part only says how each quarter differs from the average quarter.
Example
2. Standard: monthly data with a 2 by 12 moving average

A monthly series has 36 months and period 12. The classical trend needs 6 months on each side, so it exists from month 7 to month 30. The numbers are illustrative.

  1. Months with a trend: 36−12=2436 - 12 = 24, which are months 7 to 30.
  2. Months per season: each season index appears in those 24 months exactly twice, since 24/12=224 / 12 = 2.
  3. Each seasonal value is the average of its two detrended values, so every season has an estimate.
  4. The remainder exists only for months 7 to 30, so the first and last 6 months have no decomposition.
  5. Interpretation: a 36-month series gives 24 usable points for the trend and the remainder, which is why longer series give more reliable decompositions.

Try it: a monthly series runs for 60 months. How many months have a trend estimate, and how many detrended values does each season have? Answer: 60−12=4860 - 12 = 48 months have a trend, and 48/12=448 / 12 = 4 detrended values fall in each season.

Example
3. Realistic: daily electricity demand with a weekly cycle

A utility has three years of daily demand, with a weekly period of 7 days. Because 7 is odd, the centred moving average is a single window of 7 days, with 3 days on each side. The numbers are invented for illustration.

  1. Days in three years: 3×365=10953 \times 365 = 1095.
  2. Days with a trend: 1095−6=10891095 - 6 = 1089, since 3 days are lost at each end.
  3. Each weekday has about 1089/7≈1551089 / 7 \approx 155 detrended values, so the weekly seasonal value for each weekday is an average over about 155 days.
  4. The seasonal values show the weekly rhythm, for example higher weekday demand than weekend demand.
  5. The remainder is examined for spikes. A public holiday falling on a weekday shows as a large negative remainder, because demand fell below what the trend and the weekly pattern predict.
  6. Interpretation: the decomposition separates a growing trend and a steady weekly rhythm from the days that break the pattern, so the utility can plan capacity from the trend and treat the remainder as events to explain.

Try it: a utility has two years of daily data, with the same weekly period. How many days have a trend estimate? Answer: 730−6=724730 - 6 = 724 days.

Common mistakes and tradeoffs

It is tempting to think a decomposition is the true trend and the true season. In fact the parts depend on the method and on the period chosen. Different methods, such as the classical moving-average method and the robust STL method, can give different trends for the same data, and none is the uniquely correct one.

It is tempting to think the additive form always fits. In fact if the seasonal swings grow as the level grows, the additive model mixes up the trend and the season. Use the multiplicative form, or take logarithms and decompose again.

It is tempting to think the remainder is always just noise. In fact the remainder can hide structure, such as holidays, a level shift, or a seasonal pattern that changes over the years. Check it for patterns, for example with the autocorrelation function, before trusting it.

It is tempting to think decomposition makes a forecast. In fact it describes the past. To forecast, each component needs its own assumption, such as a trend that continues and a season that repeats, and those assumptions must be tested.

MethodTrend estimateNotes
Classical additiveCentred moving averageSimple and transparent, but the seasonal pattern is fixed over time
Classical multiplicativeCentred moving average on the original scaleFor swings that grow with the level
STLRepeated local regression (local regression)Lets the seasonal pattern change and resists outliers

When to use it. Use decomposition to describe a series with a clear season, to seasonally adjust before comparing periods, and to spot unusual values in the remainder.

When not to use it. Avoid it when the series is too short for even a few seasons, or when the seasonal pattern is so irregular that a single average season misleads.

History

Early in the twentieth century economists and statisticians tracking business activity began separating the regular calendar effects from the underlying movement of the economy. Methods based on ratios to moving averages became the standard for decades, and statistics offices used them to publish seasonally adjusted figures.

In 1990 Cleveland and colleagues introduced STL, a method that estimates the trend and seasonal parts with repeated local regression. It was designed to cope with seasonal patterns that change over time and with outliers, and it has since become one of the common tools in applied time series work. Its ideas are the same as the classical method: a trend, a season and a remainder, estimated in turn.

Recap

  • A time series is split into trend, seasonal and remainder, in the additive form yt=Tt+St+Rty_t = T_t + S_t + R_t, or the multiplicative form when swings grow with the level.
  • The classical method estimates the trend by a centred moving average, removes it, averages the detrended values by season, centres the seasons, and takes what remains as the remainder.
  • The trend and the remainder have no estimate at the ends of the series, which is why longer series give more usable points.
  • Decomposition describes the past, so forecasting needs an explicit assumption for each component.
  • Read next: Stationary Process for the statistical assumptions that decomposed series often need, and Autocorrelation Function for checking the remainder.

Check yourself

QuestionRecall: in the additive model, what are the three parts, and what property must the seasonal part have?Show answer
The parts are the trend, the seasonal component and the remainder, so that yt=Tt+St+Rty_t = T_t + S_t + R_t. The seasonal part repeats with the period and is centred so that its values sum to zero over one period.
QuestionComputation: a quarterly series has averaged seasonal values (2,−1,0,3)(2, -1, 0, 3). What are the centred values?Show answer
The sum is 2−1+0+3=42 - 1 + 0 + 3 = 4, so the shift is 4/4=14 / 4 = 1. Subtracting 1 from each gives (1,−2,−1,2)(1, -2, -1, 2), which sums to 1−2−1+2=01 - 2 - 1 + 2 = 0.
QuestionWhy: why does the classical trend leave the first and last few points without an estimate?Show answer
The centred moving average needs points on both sides of each time. For period pp it needs p/2p/2 points on each side, so the first and last p/2p/2 times cannot be centred. Those times have no trend, and therefore no seasonal estimate or remainder, until more data is added.
QuestionApplied: a monthly sales series grows from 100 to 400 over ten years, and its December peak grows from 20 to 80 above the trend. Which form should be used, and why?Show answer
The seasonal swings grow with the level, so the multiplicative form, yt=TtStRty_t = T_t S_t R_t, fits better. Taking logarithms and decomposing additively is an equivalent route. With the additive form, the early and late seasons would be estimated on different scales, and the seasonal pattern would be misstated.

Sources