Resources For Teachers For Tutors For Students & Parents AI New Books Pricing
Year 12 Maths - General (Unit 3 & Unit 4) Investigating and modelling time series data

Smoothing with moving medians

20 practice questions 0 video lessons Theory + worked examples

See how moving medians calm a jumpy time series plot in Year 12 VCE General Mathematics. Weekly visitor numbers at a Ballarat attraction can leap about, and one huge day, such as a festival or a voucher sale, can drag an average a long way. Picking the middle value of each group of neighbouring points avoids that problem.

You will practise 3-median and 5-median smoothing straight from a graph: choosing the middle point of each group, plotting it at the middle period and joining the smoothed points to reveal the trend. You will compare medians with means when an outlier is present, before measuring seasonal patterns with seasonal indices.

Create a free accountTrack your progress and save your work as you go.
Create free account

Theory

Moving medians smooth a time series plot by picking the middle of each group of neighbouring points. This Year 12 General Mathematics guide for students in Victoria shows how to do 3-median and 5-median smoothing straight from a plot, why medians are not thrown off by outliers, and how the smoothed series reveals the trend.

When a time series plot has large ups and downs, the long-term trend can be hard to see. Moving median smoothing replaces each point with the middle value of that point and its neighbours, and it can be done straight from the plot, without any calculation.

In 3-median smoothing, look at a point and the point on each side; the smoothed value is the one in the middle when the three are put in size order (on the plot, the one in the middle vertically). 5-median smoothing uses two points on each side and takes the third value in size order. Moving median smoothing always uses an odd number of points, so each group has a middle time period where the smoothed value is placed.

A median depends only on which value is in the middle, not on how extreme the others are, so a one-off outlier has little or no effect on median smoothing. The first and last periods have no smoothed value, because a full group does not fit there.

Key idea. The 3-median smoothed value at a period is the middle value, in size order, of that point and its two neighbours, placed at that period. More points (5 instead of 3) give a smoother series.
Weekly bookings with 3-median smoothingNine weekly values 14, 20, 16, 22, 18, 24, 22, 28, 24 (solid) and the 3-median smoothed values 16, 20, 18, 22, 22, 24, 24 for weeks 2 to 8 (dashed) 14 16 18 20 22 24 26 28 1 2 3 4 5 6 7 8 9 Week Bookings
Solid: the weekly bookings. Dashed: the 3-median smoothed values, each the middle of three neighbouring points, placed at the middle week. The zig-zag is reduced and an increasing trend shows. Weeks \(1\) and \(9\) have no smoothed value.
3-median smoothing ignores a one-off spikeNine daily values with a single spike to 65 on day 5 (solid); the dashed 3-median smoothed values stay at 30 to 40 and do not follow the spike 30 35 40 45 50 55 60 65 1 2 3 4 5 6 7 8 9 Day Visitors (hundreds)
The spike on day \(5\) is never the middle of any three neighbouring points, so the 3-median smoothed values (dashed) ignore it completely. A 3-mean for day \(5\) would be pulled up to about \(46.7\).

For a \(k\)-median, with \(k\) odd, the smoothed value at period \(t\) is

\[\text{smoothed value} = \text{middle value (in size order) of the } k \text{ points centred on } t\]
smoothed value=median of the k points centred on t

For a 3-median it is the 2nd of the three in size order; for a 5-median, the 3rd of the five. With \(n\) points in the series:

\[\text{number of smoothed values} = n - k + 1\]
number of smoothed values=n−k+1
SmoothingPoints each sideNo smoothed value forExample: \(n = 12\)
3-median\(1\)first \(1\) and last \(1\) period\(10\) values (periods \(2\) to \(11\))
5-median\(2\)first \(2\) and last \(2\) periods\(8\) values (periods \(3\) to \(10\))
Tied values. If two of the three points are level, the middle value is that repeated value: the middle of \(11, 11, 14\) is \(11\).

3-median smoothing from a plot

  1. Start at the second point. Look at it and the points on either side.
  2. Choose the middle one vertically (neither the highest nor the lowest). Read its value from the grid.
  3. Mark the smoothed value at the middle period, at that height.
  4. Move along one point and repeat, up to the second-last point. Join the smoothed points in order.

5-median smoothing

  1. Start at the third point; use it and two points on each side.
  2. The smoothed value is the third of the five in size order, placed at the middle period.
  3. Describe the trend the smoothed series shows. Use median smoothing when the data contain an outlier, and more points for a smoother result.
Example 1 β€” Read 3-median smoothed values from a plot
The plot shows the number of surf lessons given at Anglesea on seven days. Each value is a whole number. (i) Find the 3-median smoothed value for day \(3\). (ii) Find the 3-median smoothed value for day \(5\). (iii) Why is there no 3-median smoothed value for day \(1\)?
Example 1: daily surf lessons at AngleseaSeven daily values: 8, 12, 9, 14, 11, 11, 15 8 9 10 11 12 13 14 15 1 2 3 4 5 6 7 Day Lessons
Solution

Take the day and the days either side, and choose the middle value in size order.

\(\text{period 3 and neighbours}\)\(:\)\(12,\ 9,\ 14\)
\(\text{in size order}\)\(:\)\(9,\ 12,\ 14\)
\(\text{3-median (period 3)}\)\(=\)\(12\)
\(\text{period 5 and neighbours}\)\(:\)\(14,\ 11,\ 11\)
\(\text{in size order}\)\(:\)\(11,\ 11,\ 14\)
\(\text{3-median (period 5)}\)\(=\)\(11\)

(i) \(12\). (ii) Two of the points are level at \(11\), so the middle value is \(11\). (iii) Day \(1\) has no point before it, so there is no group of three centred on it.

Example 2 β€” Smooth a whole plot and describe the trend
The plot shows the number of members of a Wodonga tennis club in each of nine months. Each value is an even whole number. Use 3-median smoothing to smooth the series, draw the smoothed series and describe the trend.
Example 2: monthly members of a Wodonga tennis clubNine monthly values: 44, 36, 42, 40, 34, 38, 30, 34, 28 28 30 32 34 36 38 40 42 44 1 2 3 4 5 6 7 8 9 Month Members
Solution

Work along the plot from month \(2\) to month \(8\), each time choosing the middle of three points.

\(\text{month 2}\)\(:\)\(44,\ 36,\ 42 \to 42\)
\(\text{month 3}\)\(:\)\(36,\ 42,\ 40 \to 40\)
\(\text{month 4}\)\(:\)\(42,\ 40,\ 34 \to 40\)
\(\text{month 5}\)\(:\)\(40,\ 34,\ 38 \to 38\)
\(\text{month 6}\)\(:\)\(34,\ 38,\ 30 \to 34\)
\(\text{month 7}\)\(:\)\(38,\ 30,\ 34 \to 34\)
\(\text{month 8}\)\(:\)\(30,\ 34,\ 28 \to 30\)
Example 2: the 3-median smoothed seriesThe nine monthly values (solid) with the 3-median smoothed values 42, 40, 40, 38, 34, 34, 30 for months 2 to 8 (dashed) 28 30 32 34 36 38 40 42 44 1 2 3 4 5 6 7 8 9 Month Members

The smoothed values are \(42,\ 40,\ 40,\ 38,\ 34,\ 34,\ 30\). They never rise, while the original data zig-zag, so the smoothed series shows a clear decreasing trend.

Example 3 β€” 5-median smoothing
The plot shows the number of rides (tens) on a Ballarat tourist tram in each of \(11\) weeks. Each value is a multiple of \(5\). (i) Find the 5-median smoothed value for week \(3\). (ii) Find the 5-median smoothed value for week \(8\). (iii) How many 5-median smoothed values can be found, and for which weeks?
Example 3: weekly rides on a Ballarat tourist tramEleven weekly values: 50, 65, 55, 70, 45, 60, 75, 65, 80, 70, 85 45 50 55 60 65 70 75 80 85 1 2 3 4 5 6 7 8 9 10 11 Week Rides (tens)
Solution

Use the week and two weeks on each side, and take the third value in size order.

\(\text{period 3 and neighbours}\)\(:\)\(50,\ 65,\ 55,\ 70,\ 45\)
\(\text{in size order}\)\(:\)\(45,\ 50,\ 55,\ 65,\ 70\)
\(\text{5-median (period 3)}\)\(=\)\(55\)
\(\text{period 8 and neighbours}\)\(:\)\(60,\ 75,\ 65,\ 80,\ 70\)
\(\text{in size order}\)\(:\)\(60,\ 65,\ 70,\ 75,\ 80\)
\(\text{5-median (period 8)}\)\(=\)\(70\)
\(\text{number}\)\(=\)\(11 - 5 + 1\)
\(\text{number}\)\(=\)\(7\)

(i) \(55\) tens. (ii) \(70\) tens. (iii) \(7\) values, for weeks \(3\) to \(9\): weeks \(1\), \(2\), \(10\) and \(11\) do not have two neighbours on each side.

Example 4 β€” Median or mean when there is an outlier?
The number of bookings at a Daylesford day spa is shown for seven days. A one-off voucher sale was held on day \(4\).
Day1234567
Bookings27292671302831
(i) Find the 3-median smoothed value for day \(4\). (ii) Find the 3-mean smoothed value for day \(4\), correct to one decimal place. (iii) Which smoothed value better shows the usual level of bookings?
Solution

Both use days \(3\), \(4\) and \(5\).

\(\text{period 4 and neighbours}\)\(:\)\(26,\ 71,\ 30\)
\(\text{in size order}\)\(:\)\(26,\ 30,\ 71\)
\(\text{3-median (period 4)}\)\(=\)\(30\)
\(\text{3-mean (day 4)}\)\(=\)\(\dfrac{26 + 71 + 30}{3}\)
\(\text{3-mean (day 4)}\)\(=\)\(\dfrac{127}{3}\)
\(\text{3-mean (day 4)}\)\(\approx\)\(42.3\)

(i) \(30\). (ii) \(42.3\). (iii) The other days have \(26\) to \(31\) bookings. The outlier (\(71\)) pulls the mean up, but the median ignores how extreme it is, so the 3-median (\(30\)) better shows the usual level.

Common pitfalls

Middle in size, not middle in time. For days \(2\), \(3\) and \(4\) with values \(40, 52, 46\), the 3-median is \(46\), not \(52\) (the value of the middle day). Put the three in size order first.
Place the smoothed value at the middle period. The median of weeks \(4\), \(5\) and \(6\) is plotted at week \(5\), whichever of the three points it came from.
Odd numbers only, and no end values. Median smoothing uses \(3\) or \(5\) points. With 5-median smoothing the first two and last two periods have no smoothed value.

Frequently asked questions

How do you do moving median smoothing on a graph?

For each point, look at it and its neighbours (one on each side for a 3-median, two on each side for a 5-median). Pick the one in the middle vertically and mark that value at the middle time period. Move along one point and repeat, then join the smoothed points.

Why does moving median smoothing use an odd number of points?

With an odd number of points there is a middle time period, so the median can be placed exactly on one of the original periods and read straight from the graph.

When is median smoothing better than mean smoothing?

When the data contain an outlier. A mean is pulled towards an extreme value, but a median is only the middle value, so a single one-off spike or dip has little or no effect on it.

Is 5-median smoothing smoother than 3-median smoothing?

Usually yes. Each smoothed value depends on more neighbouring points, so single high or low points have less effect. The cost is fewer smoothed values at each end.

How many smoothed values do I get with median smoothing?

With n points and k-median smoothing you get n - k + 1 values. For 9 points, 3-median smoothing gives 7 values and 5-median smoothing gives 5.