Smoothing with moving averages
Learn how moving averages smooth a bumpy time series in Year 12 General Mathematics for Queensland (QCAA). Daily crowds at a Sunshine Coast beach or weekly sales at a Brisbane market jump around from one period to the next, and averaging neighbouring values cuts through that noise so the real direction is easier to see.
You will practise calculating 3-point and 5-point moving means and moving medians, placing each one on the middle period, choosing a median when an outlier is present, and building the same calculations in a spreadsheet. Next, seasonal indices remove a repeating calendar pattern from the data.
Theory
Moving averages smooth out the random ups and downs in a time series so the trend stands out. This Year 12 General Mathematics guide for Queensland students shows how to calculate 3-point and 5-point moving means and medians, centre them correctly and set them up in a spreadsheet.
Real time series data jump up and down from one period to the next, which can hide the overall pattern. Smoothing replaces each value with an average of the values around it, so the random ups and downs (irregular fluctuations) shrink and the trend is easier to see.
A \(k\)-point moving mean is the mean of \(k\) consecutive values; a \(k\)-point moving median is the middle value of \(k\) consecutive values once they are sorted. Here \(k\) is always an odd number, usually \(3\) or \(5\), so each window has a middle time period and the smoothed value is placed (centred) on that period.
The window then moves along one period at a time, giving a new smoothed value for each period. There are no smoothed values for the first and last \(\dfrac{k-1}{2}\) periods, because a full window does not fit there.
A 3-point and a 5-point moving mean centred on time period \(t\), where \(y_t\) is the value at period \(t\):
The moving median uses the same window but takes the middle value after sorting. With \(n\) values and a \(k\)-point window:
In a spreadsheet (time in column A, data in column B starting in row 2, smoothed values in column C):
| Smoothing | Formula in the row for period \(t\) (row \(r\)) |
|---|---|
| 3-point moving mean | =AVERAGE(B(r−1):B(r+1)), e.g. =AVERAGE(B2:B4) in C3 |
| 5-point moving mean | =AVERAGE(B(r−2):B(r+2)), e.g. =AVERAGE(B2:B6) in C4 |
| 3-point moving median | =MEDIAN(B(r−1):B(r+1)), e.g. =MEDIAN(B2:B4) in C3 |
Fill the formula down column C; leave the cells where a full window does not fit empty.
Calculating a moving mean or median
- Pick the window. For a 3-point value centred on period \(t\), use \(t-1\), \(t\) and \(t+1\); for 5 points use \(t-2\) to \(t+2\).
- Mean: add the values in the window and divide by the number of points. Median: sort the values in the window and take the middle one.
- Place the answer on the middle period of the window, and round (usually to \(1\) decimal place) only at the end.
- Slide the window on by one period and repeat until the window reaches the last value.
Interpreting the smoothed series
- Plot the smoothed values on the same axes as the data, at their middle periods.
- Describe the trend the smoothed line shows, now that the irregular fluctuations are reduced.
- If the data contain an outlier, prefer a moving median; for a smoother line, use more points (5 rather than 3).
| Week | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
|---|---|---|---|---|---|---|---|
| Jars sold | 34 | 41 | 38 | 45 | 40 | 49 | 44 |
The window centred on week \(2\) is weeks \(1\), \(2\) and \(3\).
| \(\text{mean}_2\) | \(=\) | \(\dfrac{34 + 41 + 38}{3}\) |
| \(\text{mean}_2\) | \(=\) | \(\dfrac{113}{3}\) |
| \(\text{mean}_2\) | \(\approx\) | \(37.7\) |
| \(\text{number}\) | \(=\) | \(n - k + 1 = 7 - 3 + 1\) |
| \(\text{number}\) | \(=\) | \(5\) |
(i) \(37.7\) jars. (ii) \(5\) moving means, for weeks \(2\) to \(6\) (weeks \(1\) and \(7\) have no full window).
| Week | 2 | 3 | 4 | 5 | 6 |
|---|---|---|---|---|---|
| 3-point mean | \(37.7\) | \(41.3\) | \(41\) | \(44.7\) | \(44.3\) |
(iii) The moving means rise overall from \(37.7\) to \(44.3\), with only tiny dips: an increasing trend.
| Day | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
|---|---|---|---|---|---|---|---|---|---|
| Swimmers | 86 | 92 | 88 | 95 | 31 | 97 | 93 | 101 | 98 |
Use days \(1\) to \(5\) for day \(3\), and days \(3\) to \(7\) for day \(5\). Sort before taking a median.
| \(\text{days 1-5 sorted}\) | \(:\) | \(31,\ 86,\ 88,\ 92,\ 95\) |
| \(\text{median}_3\) | \(=\) | \(88\) |
| \(\text{days 3-7 sorted}\) | \(:\) | \(31,\ 88,\ 93,\ 95,\ 97\) |
| \(\text{median}_5\) | \(=\) | \(93\) |
| \(\text{mean}_5\) | \(=\) | \(\dfrac{88 + 95 + 31 + 97 + 93}{5}\) |
| \(\text{mean}_5\) | \(=\) | \(\dfrac{404}{5}\) |
| \(\text{mean}_5\) | \(=\) | \(80.8\) |
(i) \(88\). (ii) Median \(93\), mean \(80.8\).
(iii) The storm value \(31\) is an outlier. It drags the mean down to \(80.8\), well below the normal level of about \(90\), but the median ignores it, so the moving median (\(93\)) is better here.
| A | B | C | |
|---|---|---|---|
| 1 | Month | Orders | 5-point moving mean |
| 2 | Jan | 212 | |
| 3 | Feb | 198 | |
| 4 | Mar | 225 | =AVERAGE(B2:B6) |
| 5 | Apr | 240 | |
| 6 | May | 231 | |
| 7 | Jun | 256 | |
| 8 | Jul | 249 | |
| 9 | Aug | 270 |
Row 4 is March (the 3rd month); a 5-point window reaches two rows up and two rows down.
| \(\text{C4}\) | \(:\) | \(\text{mean of B2 to B6 (Jan to May), centred on Mar}\) |
| \(\text{C4}\) | \(=\) | \(\dfrac{212 + 198 + 225 + 240 + 231}{5}\) |
| \(\text{C4}\) | \(=\) | \(\dfrac{1106}{5}\) |
| \(\text{C4}\) | \(=\) | \(221.2\) |
| \(\text{C7}\) | \(:\) | \(\texttt{=AVERAGE(B5:B9)}\) |
| \(\text{C7}\) | \(=\) | \(\dfrac{1246}{5}\) |
| \(\text{C7}\) | \(=\) | \(249.2\) |
(i) C4 averages the five months January to May and places the result on March: \(221.2\). (ii) C2, C3 (January, February) and C8, C9 (July, August) stay empty, because a 5-point window does not fit. (iii) =AVERAGE(B5:B9), displaying \(249.2\).
| Week | 1 | 2 | 3 | 4 | 5 | 6 |
|---|---|---|---|---|---|---|
| Bookings | 58 | \(x\) | 67 | 63 | 72 | 70 |
The three values centred on week \(2\) must add to \(3 \times 61\).
| \(\dfrac{58 + x + 67}{3}\) | \(=\) | \(61\) |
| \(58 + x + 67\) | \(=\) | \(183\) |
| \(x\) | \(=\) | \(183 - 125\) |
| \(x\) | \(=\) | \(58\) |
| \(\text{mean}_3\) | \(=\) | \(\dfrac{58 + 67 + 63}{3} \approx 62.7\) |
| \(\text{mean}_4\) | \(=\) | \(\dfrac{67 + 63 + 72}{3} \approx 67.3\) |
| \(\text{mean}_5\) | \(=\) | \(\dfrac{63 + 72 + 70}{3} \approx 68.3\) |
(i) \(x = 58\) bookings. (ii) The moving means \(61,\ 62.7,\ 67.3,\ 68.3\) rise every week, so the bookings show an increasing trend.
Common pitfalls
Frequently asked questions
Why do we smooth a time series?
Smoothing averages out the random, short-term ups and downs so that the long-term trend is easier to see and describe.
How do I calculate a 3-point moving mean?
Add the value for the period you want and the values just before and just after it, divide by 3, and place the answer on that middle period. Then move the window along one period and repeat.
When should I use a moving median instead of a moving mean?
Use a moving median when the data contain an outlier, such as a one-off spike or dip. The median is the middle value of the sorted window, so a single extreme value has little effect on it.
Why does the number of points have to be odd?
With an odd number of points, such as 3 or 5, the window has a middle time period, so each smoothed value can be placed exactly on one of the original periods.
How many moving averages can I calculate?
With n values and a k-point window you get n - k + 1 smoothed values. For example, 12 quarterly values smoothed with a 5-point moving mean give 8 moving means.
What formula do I use in a spreadsheet?
If the data are in column B, a 3-point moving mean centred on row 3 is =AVERAGE(B2:B4), and a 5-point moving median centred on row 4 is =MEDIAN(B2:B6). Fill the formula down the column.