Median Formula for Continuous Grouped Data

The formula nobody explains

Every statistics textbook hands you this and moves on:

\[ \mathrm{Md} = L + \frac{i}{f}\left(\frac{N}{2} - cf\right) \]

where \(L\) is the lower boundary of the median class, \(i\) is the class width, \(f\) is the frequency of the median class, \(N\) is the total number of observations, and \(cf\) is the cumulative frequency of the class before the median class.

Most of it is intuitive once you accept that the median sits somewhere inside one particular class. The part that trips people up is the \(N/2 - cf\) term. Why subtract \(cf\) at all? The cleanest way to see it is to stop thinking in formulas and think in a line of kids.

Setting the scene

Imagine every kid in a school lined up by height, shortest to tallest. There are 34 kids. The median is the height of the kid standing exactly in the middle - position \(N/2 = 17\) in the line.

Nobody measured each kid individually. All we have is a grouped record:

Height (cm)Frequency \(f\)Cumulative frequency \(cf\)
140-15066
150-160915
160-170823
170-1801134

\(cf\) is just a running total - "how many kids have I passed by the time I reach the end of this group."

Step 1: Find which group is hiding the median

Walk down the cumulative column until it first reaches or passes 17. After the 150-160 group, only 15 kids have gone by - not enough. After the 160-170 group, 23 have gone by - that's enough, and it includes the 17th.

So the median kid is standing somewhere inside the 160-170 group. That fixes \(L = 160\), \(i = 10\), \(f = 8\).

Step 2: Why \(N/2 - cf\), not just \(N/2\)

This is the part the textbook skips. Picture yourself standing at the gate of the 160-170 group. Behind you, 15 kids have already walked past - they belong to earlier groups, and they are done, counted, irrelevant from here on.

You don't need "the 17th kid overall" anymore. You need a much smaller question: starting from this gate, how many more kids do I have to count to reach the 17th one?

\[ 17 - 15 = 2 \]

That subtraction - \(N/2 - cf\) - is exactly that question. It converts a global rank (17th in the whole line) into a local rank (2nd inside this group). The 15 kids before the gate stop mattering the moment you cross it.

Step 3: Turning "2 more kids" into centimetres

You still don't know the exact height of any kid in this group - only that 8 of them are squeezed somewhere across a 10 cm stretch. The fairest assumption available is that they're spread evenly across it. So each step forward is worth:

\[ \frac{i}{f} = \frac{10}{8} = 1.25 \]

That's 1.25 cm per kid. Walking forward 2 kids costs:

\[ \frac{i}{f}\left(\frac{N}{2} - cf\right) = 1.25 \times 2 = 2.5 \]

2.5 cm past the gate.

Putting it together

\[ \boxed{\mathrm{Md} = L + \frac{i}{f}\left(\frac{N}{2} - cf\right)} \]

Verification.

\[ \mathrm{Md} = 160 + \frac{10}{8}\left(17 - 15\right) = 160 + 2.5 = 162.5 \]

Real-life pieceFormula term
Gate where you start counting\(L\)
Kids already passed before the gate\(cf\)
Position you're hunting for, overall\(N/2\)
Steps left to take, once at the gate\(N/2 - cf\)
Width of one step\(i/f\)

Why the answer can never spill outside the class

A natural worry: could \(\frac{i}{f}\left(\frac{N}{2}-cf\right)\) ever come out bigger than \(i\), pushing the median past the group it supposedly lives in? It can't, and the reason is baked into how the median class was chosen in the first place. The class is selected precisely because its cumulative frequency is the first one to reach or exceed \(N/2\):

\[ cf_{\mathrm{before}} < \frac{N}{2} \le cf_{\mathrm{before}} + f \]

Rearranging the right-hand side gives \(\frac{N}{2} - cf_{\mathrm{before}} \le f\), and multiplying both sides by \(i/f\):

\[ \frac{i}{f}\left(\frac{N}{2}-cf_{\mathrm{before}}\right) \le i \]

So the formula is self-consistent: it is mathematically guaranteed to land the median somewhere between \(L\) and \(L+i\), never past it.

The takeaway

The whole formula is one sentence: start at the gate, work out how many you still need now that the earlier groups are already counted, then walk that many steps at a fixed step size. The same "subtract what's already counted" move is exactly what happens when computing quartiles, deciles, or any percentile from grouped data - only the target rank changes from \(N/2\) to something like \(N/4\) or \(kN/100\). Once the line-of-kids picture clicks for the median, the rest of percentile arithmetic is the same trick repeated.

Previous:
Pitfalls for MathJax in HUGO
Next:
The Kid Who Discovered Machine Learning