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.
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 . 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 is
The wider the window, the more noise it removes: for white noise, a width of divides the standard deviation by . But it also blurs: peaks are flattened and sharp steps are smeared over the window’s width, and the first and last values have no full window.
Exponential smoothing
A moving average forgets values all at once when they leave the window. Exponential smoothing forgets gradually:
with a smoothing constant between 0 and 1. Unrolled, the weights on the present and past values are , , and so on: a fading memory, about 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 .
Here 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 :
The bandwidth 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.
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 , 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 and the kernel’s bandwidth, the moving average’s own spread . 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.
- 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 at the two ends and on the 11 months between, adding to 1. For quarters it is the same with 4.
- Remove the trend and average what is left month by month: that is the profile .
- Recentre the profile so its values over one period add to 0, so that removing it does not shift the level.
- Subtract it: the adjusted series is .
A quicker way to remove a season of period is the seasonal difference : this January minus last January. It removes any pattern that repeats every 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 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 , starting from , 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 cuts white-noise variance to a third, , 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 of Linear regression, smooth at the middle value. A box of width 3 gives . A Gaussian kernel with weights the offsets , , by , and , and gives .
4. Quarterly data, no noise. Three years of quarterly values with trend and season are 7, 14, 19, 10, then 11, 18, 23, 14, then 15, 22, 27, 18. The centred average over four quarters at , with half weights at the ends, is , exactly the trend; at it is 14. Removing the trend leaves in every year, already adding to 0. The adjusted series is , a straight line. The seasonal difference is 4 for every 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 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
| Quantity | Formula | Notes |
|---|---|---|
| Moving average | width : noise SD ; blurs | |
| Exponential smoothing | memory about ; trails | |
| Noise cut, exponential | SD | : variance |
| Kernel smoothing | bandwidth | |
| Trend for a period | centred average over one period | for months |
| Seasonal profile | average of trend-removed values by season, recentred to sum 0 | |
| Adjusted series | ||
| Seasonal difference | removes period ; trend becomes constant |