How to calculate median via interpolation I am reading a text on data mining. I came across this formula, but I do not understand how to apply it. There aren't any examples following the forumla and my research online has produced very few results. Can someone explain how to apply this formula?


Let's suppose we have three groups
0-20000       20 
20000-39999   60
40000-        20 

where the second column is frequency, and also percent. The median must be within the second group as $20\%$ are less and $20\%$ are more.
Then the recipe gives
$20000 + [(50 - 20) / 60] \times 20000$
which is $20000 + 0.5 \times 20000 = 30000.$
which is halfway through the median interval, as it should be: I deliberately made the example really simple (and symmetric). If we had instead
0-20000       25
20000-39999   60
40000-        15

so that the recipe yields
$20000 + [(50 - 25) / 60] \times 20000 \approx 31667$
it should be clear that the median should be nearer the lower end of its interval than the top, because the cumulative probability at the bottom ($25\%$) is nearer $50\%$ than is the cumulative probability at the top ($85\%$).
It may help to draw cumulative bar charts with simple numerical examples and consider interpolation geometrically.
Let's spell it out: the assumption here is that within each bin, the distribution is uniform. If there are lots of bins, that assumption may work well. Otherwise it is not necessarily the only alternative. For example if all upper bin limits are positive, and the distribution is right or positively skewed, then interpolation on the logarithms of upper bin limits may work better.
