Skip to content

Smoothing and seasonality

Averaging neighbours removes noise at the price of lag and blur, and averaging month by month finds a seasonal pattern that can be subtracted.

Helps to know first
This topic

First, the picture

Five years of monthly data, each year laid over the last. Watch their average become a seasonal pattern, then disappear.

Taking out the seasons

Five years of monthly values: a slow rise, a yearly cycle and noise (seed 10300).

Five years of monthly values: a slow rise, a yearly cycle, and noise. Remove the rise and lay each year over the same twelve months.

years stacked
0
profile off by (rms)
–
spread left
–
0.00 / 12.00 s
Describe this picture

Two panels, side by side on a wide screen (stacked on a phone). Five years of seeded monthly values (seed 10300): a slow rise of 0.5 a month from 100, a yearly cycle of height 10, and noise of standard deviation 2. In the clip, over about 10 seconds, the years are drawn one by one as five thin lines stacked on one January-to-December axis, with the rise removed; their month-by-month average appears as a thick curve, the seasonal profile. The second panel shows the full series as a thin line with the rise dashed; the profile is subtracted from every month and the adjusted series is drawn over it, a rising line with noise. Readouts give the years stacked, how far the profile is from the true cycle (root mean square, 0.580 with five years) and the spread left in the adjusted series about the rise (1.800). After the clip a slider sets how many years are stacked, from 1 to 5.

Taking out the seasons

Ice-cream sales rise every summer; heating bills rise every winter. A pattern that repeats with the calendar is a season, and it can hide what the series is really doing. Is this July’s rise the usual summer, or something new?

The picture answers by stacking. Lay each year over the last, and the noise of one year is not the noise of the next, while the season is the same every year. So the month-by-month average keeps the season and shrinks the noise: averaging 5 years cuts the noise’s standard deviation from 2 to 2/5=0.8942/\sqrt5=0.894. That average is the seasonal profile. Subtract it, and what is left is the seasonally adjusted series.

After the clip, drag the number of years. With one year the profile is mostly that year’s noise; with five it settles.

Moving averages

Replace each value by the average of itself and its neighbours. A centred moving average of width 2r+12r+1 is

mk=12r+1∑i=−rrxk+i.m_k=\frac{1}{2r+1}\sum_{i=-r}^{r}x_{k+i}.

The wider the window, the more noise it removes: for white noise, a width of ww divides the standard deviation by w\sqrt w. But it also blurs: peaks are flattened and sharp steps are smeared over the window’s width, and the first and last rr values have no full window.

Exponential smoothing

A moving average forgets values all at once when they leave the window. Exponential smoothing forgets gradually:

mk=α xk+(1−α) mk−1,m_k=\alpha\,x_k+(1-\alpha)\,m_{k-1},

with a smoothing constant α\alpha between 0 and 1. Unrolled, the weights on the present and past values are α\alpha, α(1−α)\alpha(1-\alpha), α(1−α)2\alpha(1-\alpha)^2 and so on: a fading memory, about 1/α1/\alpha samples long. It needs only the last level, so it runs as data arrive, but it looks only backwards, so it trails a rising series. For white noise it multiplies the standard deviation by α/(2−α)\sqrt{\alpha/(2-\alpha)}.

Here α\alpha is this page’s smoothing constant; on the testing pages it was a false-alarm chance.

Kernel smoothing

A kernel smoother takes a weighted average with weights that fall off smoothly with distance, for example the Gaussian kernel Kh(u)=e−u2/(2h2)K_h(u)=e^{-u^2/(2h^2)}:

mk=∑iKh(k−i) xi∑iKh(k−i).m_k=\frac{\sum_iK_h(k-i)\,x_i}{\sum_iK_h(k-i)}.

The bandwidth hh sets how far the weights reach, as the window width does for a moving average. Choosing it is the overfitting question of Overfitting and model choice: too small follows the noise, too large loses the shape.

Three ways to smooth

A noisy step and spike smoothed three ways, each with its gain at every frequency (seed 10301).

A noisy series with a sudden step and a single spike, smoothed three ways, with each smoother's gain at every frequency beside it.

width w
3
exponential α
0.500
kernel bandwidth
0.82
0.00 / 9.80 s
Describe this picture

Three rows, one per smoother: a moving average, exponential smoothing and a Gaussian kernel. Each row smooths the same noisy series of 120 samples (seed 10301), which holds a sudden step at sample 40 and a single spike at sample 85, drawn as faint dots under the smoothed line; beside it, a small panel draws the smoother’s gain from frequency 0 to π\pi, which lets slow changes through and holds fast ones back. In the clip the width grows from 3 to 15 samples in steps of 2: the noise falls, the step is smeared, the spike is flattened, and the exponential smoother’s output trails behind the step. Readouts give the width, the exponential constant α=2/(w+1)\alpha=2/(w+1) and the kernel’s bandwidth, the moving average’s own spread (w2−1)/12\sqrt{(w^2-1)/12}. After the clip one slider, “Width, samples”, sets the width, from 3 to 15 samples, with these matching settings for the other two.

The seasonal profile, step by step

The classical recipe for monthly data has four steps.

  1. Find the trend with a centred moving average one period wide, so that every month of the cycle gets equal weight. A period of 12 is even, so the centred version averages two neighbouring 12-month windows: weights 124\tfrac1{24} at the two ends and 112\tfrac1{12} on the 11 months between, adding to 1. For quarters it is the same with 4.
  2. Remove the trend and average what is left month by month: that is the profile gkg_k.
  3. Recentre the profile so its values over one period add to 0, so that removing it does not shift the level.
  4. Subtract it: the adjusted series is xk−gkx_k-g_k.

A quicker way to remove a season of period PP is the seasonal difference xk−xk−Px_k-x_{k-P}: this January minus last January. It removes any pattern that repeats every PP samples and turns a straight-line trend into a constant.

These are filters

Every smoother on this page is a filter: a moving average is an FIR filter with equal taps, and exponential smoothing is a one-pole recursive filter. Their frequency responses, drawn in the second picture, explain their side effects: what they let through, what they hold back, and what they delay.

Worked example

1. Smoothing a short series. For the series 1,2,4,5,4,3,2,31,2,4,5,4,3,2,3 of Time series and autocorrelation, the moving average of width 3 gives, for the six inner values: 2.333, 3.667, 4.333, 4, 3, 2.667. The peak of 5 falls to 4.333, and the series loses a value at each end.

Exponential smoothing with α=0.5\alpha=0.5, starting from m1=1m_1=1, gives these exact values: 1, 1.5, 2.75, 3.875, 3.9375, 3.46875, 2.734375, 2.8671875. It trails the data: it peaks one step after the series does, below the series’ peak.

2. The same noise reduction. Exponential smoothing at α=0.5\alpha=0.5 cuts white-noise variance to a third, 0.5/1.5=130.5/1.5=\tfrac13, as the 3-point average does. Both pass a third of the fastest wiggle, the one that flips sign every sample. The 3-point average also blocks one frequency completely, a wiggle with period 3 samples; the exponential smoother blocks nothing completely.

3. A kernel at one point. For the five values 2,4,5,4,52,4,5,4,5 of Linear regression, smooth at the middle value. A box of width 3 gives 13/3=4.33313/3=4.333. A Gaussian kernel with h=1h=1 weights the offsets 00, ±1\pm1, ±2\pm2 by 11, 0.60650.6065 and 0.13530.1353, and gives 10.7996/2.4837=4.34810.7996/2.4837=4.348.

4. Quarterly data, no noise. Three years of quarterly values with trend 10+k10+k and season −4, 2, 6, −4-4,\ 2,\ 6,\ -4 are 7, 14, 19, 10, then 11, 18, 23, 14, then 15, 22, 27, 18. The centred average over four quarters at k=3k=3, with half weights at the ends, is (3.5+14+19+10+5.5)/4=13(3.5+14+19+10+5.5)/4=13, exactly the trend; at k=4k=4 it is 14. Removing the trend leaves −4, 2, 6, −4-4,\ 2,\ 6,\ -4 in every year, already adding to 0. The adjusted series is 11,12,13,…,2211,12,13,\dots,22, a straight line. The seasonal difference xk−xk−4x_k-x_{k-4} is 4 for every kk from 5 on: the season is gone, and what is left is the trend’s rise per year.

Try it yourself. The weights of exponential smoothing at α=0.5\alpha=0.5 are 0.5, 0.25, 0.125 and so on. A width-9 moving average cuts white noise of standard deviation 3 to 1. A seasonal difference at period 4 turns a straight line rising 0.5 per sample into the constant 2.

Where you’ll meet this

Economic and energy data. Unemployment, retail sales and electricity demand are published seasonally adjusted, so that one month can be compared with the last.

Meters and gauges. A battery gauge, a speedometer’s display or an audio level meter smooths its readings, often exponentially, so the number does not flicker.

Trends under cycles. A slow drift in a sensor, hidden under a daily temperature cycle, shows up once the daily profile is subtracted.

In signal processing · smoothers are filters

A moving average is an FIR filter and exponential smoothing a one-pole IIR filter; Choosing FIR or IIR and Simple smoothing filters in the signal processing course compare them by their frequency responses, and Resonators, notches and combs shows that a seasonal difference is a comb filter, with notches at zero frequency, the season’s frequency and its harmonics.

Reference card

QuantityFormulaNotes
Moving averagemk=12r+1∑i=−rrxk+im_k=\frac1{2r+1}\sum_{i=-r}^{r}x_{k+i}width ww: noise SD ×1/w\times1/\sqrt w; blurs
Exponential smoothingmk=αxk+(1−α)mk−1m_k=\alpha x_k+(1-\alpha)m_{k-1}memory about 1/α1/\alpha; trails
Noise cut, exponentialSD ×α/(2−α)\times\sqrt{\alpha/(2-\alpha)}α=0.5\alpha=0.5: variance 13\tfrac13
Kernel smoothingmk=∑iKh(k−i)xi/∑iKh(k−i)m_k=\sum_iK_h(k-i)x_i/\sum_iK_h(k-i)bandwidth hh
Trend for a period PPcentred average over one period2×122\times12 for months
Seasonal profileaverage of trend-removed values by season, recentred to sum 0
Adjusted seriesxk−gkx_k-g_k
Seasonal differencexk−xk−Px_k-x_{k-P}removes period PP; trend becomes constant

Keep reading with a free account.

By creating an account you accept the terms of use.

Sign in

Already have an account? Use the service you signed up with.

Or keep reading: get new lessons by email

Are you 13 or over?

Accounts and email updates are for people aged 13 or over. We keep only your answer, never your date of birth.

End of the lesson

Where to go next.

Phasorium

Account

Sign inKeep your place on any device

Subjects

Site

Look