Smoothing with moving means
Find out how moving means smooth a bumpy time series in Year 12 VCE General Mathematics. Weekly ticket sales at a Bendigo theatre or monthly output at a Shepparton cannery jump about from one period to the next. Replacing each value with the mean of its neighbours cuts through that noise so the real direction is easier to see.
You will practise 3-mean and 5-mean smoothing, placing each value at the middle period, and learn why an even number of terms needs centring: averaging two neighbouring means. You will see how a 4-mean for quarterly data or a 12-mean for monthly data wipes out the seasonal pattern, before moving on to smoothing a plot with moving medians.
Theory
Moving means smooth out the large ups and downs in a time series so the trend stands out. This Year 12 General Mathematics guide for students in Victoria shows how to calculate 3-mean and 5-mean smoothed values, how centring works for 2-, 4- and 12-mean smoothing, and how to choose the number of terms.
A time series with large ups and downs can hide its long-term direction. Smoothing replaces each value with the mean of a group of neighbouring values, so the irregular fluctuations shrink and the trend is easier to see.
In 3-mean smoothing the smoothed value for a period is the mean of that value and the one on each side; 5-mean smoothing uses two on each side. An odd number of terms has a middle period, so the smoothed value is placed there. The group then moves along one period at a time. The first and last few periods have no smoothed value, because a full group does not fit.
With an even number of terms (\(2\), \(4\) or \(12\)) the mean falls halfway between two periods. Centring fixes this: average two adjacent even-term means, and the result sits exactly on a period. A 4-mean with centring for quarterly data, or a 12-mean with centring for monthly data, contains one of every season, so it also removes the seasonality.
With \(y_t\) the value at period \(t\), the smoothed values placed at period \(t\) are:
Centring a 4-mean on period \(t\): the first 4-mean (periods \(t-2\) to \(t+1\)) sits halfway between \(t-1\) and \(t\); the second (periods \(t-1\) to \(t+2\)) sits halfway between \(t\) and \(t+1\). Their mean sits on \(t\):
The same idea works for 2-means and 12-means. With \(n\) values:
| Smoothing | Number of smoothed values | Example: \(n = 12\) |
|---|---|---|
| \(k\)-mean, \(k\) odd | \(n - k + 1\) | 3-mean: \(10\); 5-mean: \(8\) |
| \(k\)-mean with centring, \(k\) even | \(n - k\) | 2-mean: \(10\); 4-mean: \(8\) |
Odd number of terms (3-mean, 5-mean)
- Pick the group. For period \(t\), use \(t-1\), \(t\), \(t+1\) (3-mean) or \(t-2\) to \(t+2\) (5-mean).
- Add and divide by the number of terms.
- Place the answer at the middle period, then slide the group on one period and repeat.
Even number of terms, with centring (2-mean, 4-mean, 12-mean)
- Find the two means that straddle period \(t\). For a 4-mean: periods \(t-2\) to \(t+1\), and periods \(t-1\) to \(t+2\).
- Average the two means. The result is the smoothed value with centring for period \(t\).
- Interpret the smoothed series: describe the trend it shows, now that the fluctuations (and, with the right number of terms, the seasonality) are removed.
| Year | 2018 | 2019 | 2020 | 2021 | 2022 | 2023 | 2024 |
|---|---|---|---|---|---|---|---|
| Visitors (thousand) | 52 | 61 | 55 | 66 | 59 | 72 | 68 |
A 3-mean uses the year and one year each side; a 5-mean uses two years each side.
| \(\text{3-mean (2019)}\) | \(=\) | \(\dfrac{52 + 61 + 55}{3}\) |
| \(\text{3-mean (2019)}\) | \(=\) | \(\dfrac{168}{3}\) |
| \(\text{3-mean (2019)}\) | \(=\) | \(56\) |
| \(\text{3-mean (2021)}\) | \(=\) | \(\dfrac{55 + 66 + 59}{3}\) |
| \(\text{3-mean (2021)}\) | \(=\) | \(\dfrac{180}{3}\) |
| \(\text{3-mean (2021)}\) | \(=\) | \(60\) |
| \(\text{5-mean (2020)}\) | \(=\) | \(\dfrac{52 + 61 + 55 + 66 + 59}{5}\) |
| \(\text{5-mean (2020)}\) | \(=\) | \(\dfrac{293}{5}\) |
| \(\text{5-mean (2020)}\) | \(=\) | \(58.6\) |
| \(\text{number of 3-means}\) | \(=\) | \(7 - 3 + 1 = 5\) |
| \(\text{number of 5-means}\) | \(=\) | \(7 - 5 + 1 = 3\) |
(i) \(56\) and \(60\) thousand. (ii) \(58.6\) thousand. (iii) \(5\) three-mean values (\(2019\) to \(2023\)) and \(3\) five-mean values (\(2020\) to \(2022\)). All the 3-mean smoothed values, correct to one decimal place:
| Year | 2019 | 2020 | 2021 | 2022 | 2023 |
|---|---|---|---|---|---|
| 3-mean | \(56\) | \(60.7\) | \(60\) | \(65.7\) | \(66.3\) |
The smoothed values rise overall from \(56\) to \(66.3\): an increasing trend.
| Week | 1 | 2 | 3 | 4 | 5 |
|---|---|---|---|---|---|
| Tickets (tens) | 62 | 70 | 74 | 80 | 78 |
Each 2-mean sits halfway between two weeks; average the 2-means on either side of week \(3\).
| \(\text{weeks 2 and 3}\) | \(:\) | \(\dfrac{70 + 74}{2} = 72\) |
| \(\text{weeks 3 and 4}\) | \(:\) | \(\dfrac{74 + 80}{2} = 77\) |
| \(\text{centred (week 3)}\) | \(=\) | \(\dfrac{72 + 77}{2}\) |
| \(\text{centred (week 3)}\) | \(=\) | \(74.5\) |
The 2-mean smoothed value with centring for week \(3\) is \(74.5\) tens. (Check: it equals \(\dfrac{70 + 2 \times 74 + 80}{4}\), because the middle week is counted twice.)
| Year | Q1 | Q2 | Q3 | Q4 |
|---|---|---|---|---|
| 2023 | 150 | 118 | 96 | 132 |
| 2024 | 158 | 122 | 104 | 140 |
Find adjacent 4-means, then average each pair.
| \(\text{Q1 to Q4 2023}\) | \(:\) | \(\dfrac{496}{4} = 124\) |
| \(\text{Q2 2023 to Q1 2024}\) | \(:\) | \(\dfrac{504}{4} = 126\) |
| \(\text{centred (Q3 2023)}\) | \(=\) | \(\dfrac{124 + 126}{2}\) |
| \(\text{centred (Q3 2023)}\) | \(=\) | \(125\) |
| \(\text{Q3 2023 to Q2 2024}\) | \(:\) | \(\dfrac{508}{4} = 127\) |
| \(\text{centred (Q4 2023)}\) | \(=\) | \(\dfrac{126 + 127}{2}\) |
| \(\text{centred (Q4 2023)}\) | \(=\) | \(126.5\) |
(i) \(125\) and \(126.5\) (\(\$\) thousand). (ii) Every 4-mean contains one of each quarter, so the busy Q1 and quiet Q3 cancel out. The smoothed values (\(125,\ 126.5,\ 128,\ 130\)) rise steadily: an increasing trend.
The middle of months \(1\) to \(12\) is \(6.5\), halfway between June and July.
| \(\text{Jan to Dec}\) | \(:\) | \(\text{sits between June and July}\) |
| \(\text{Feb to Jan}\) | \(:\) | \(\text{sits between July and August}\) |
| \(\text{centred value}\) | \(=\) | \(\dfrac{38.4 + 39.0}{2}\) |
| \(\text{centred value}\) | \(=\) | \(38.7\) |
| \(\text{number of 12-means}\) | \(=\) | \(36 - 12 + 1 = 25\) |
| \(\text{centred values}\) | \(=\) | \(25 - 1 = 24\) |
(i) \(38.7\) thousand tonnes, placed at July \(2024\). (ii) \(24\) centred values (\(36 - 12\)); the first six and last six months have none.
Common pitfalls
Frequently asked questions
Why do we smooth a time series?
Smoothing averages out the large short-term ups and downs so that the long-term trend is easier to see and describe.
How do I calculate a 3-mean smoothed value?
Add the value for the period and the values just before and just after it, divide by 3, and place the answer at that middle period. Then move along one period and repeat.
What does centring mean in moving mean smoothing?
With an even number of terms, such as 4, the mean sits halfway between two time periods. Centring averages two adjacent means so that the smoothed value sits exactly on a time period.
How do I find a 4-mean smoothed value with centring?
Find the mean of the four values from two periods before to one period after, and the mean of the four values from one period before to two periods after. The average of these two 4-means is the centred value.
Why use a 4-mean for quarterly data or a 12-mean for monthly data?
Each group then contains exactly one of every season, so the seasonal highs and lows cancel out and only the trend is left.
How many smoothed values will I get?
With n values, odd k-mean smoothing gives n - k + 1 values and even k-mean smoothing with centring gives n - k values. For 12 quarterly values, 4-mean smoothing with centring gives 8.