5
$\begingroup$

I'm sure this is a very straightforward question but it came up in my work today and I could not think of the reasoning behind it.

I had two sets of numeric values (A & B) and was looking at the median of their ratio and noticed that median(A)/median(B) is not equal to median(A/B) and I was wondering if someone could explain why not. Seems like one might assume they are equal, but this is not true. I also noted that it seems when the range of A & B respectively are small the median(A/B) is quite near median(A)/median(B), but with a large range the two values seem to diverge.

$\endgroup$
6
  • $\begingroup$ what do you mean by median (A/B). A = set of data and B = set of data, so how do you divide one set by another? $\endgroup$ Commented Apr 22, 2014 at 17:35
  • $\begingroup$ sets A and B are numeric values. edited question appropriately $\endgroup$
    – Steve Reno
    Commented Apr 22, 2014 at 17:36
  • 3
    $\begingroup$ Still not clear. Suppose A = {1,2,3} and B={4,5,6}, how do you do (A/B)? Is it A/B = {1/4, 2/5, 3/6}? Is it {1/6, 2/5, 3/4}? Is it something else? $\endgroup$ Commented Apr 22, 2014 at 17:38
  • 4
    $\begingroup$ Doesn't this present at least one answer to your question though? You can reorder A and B however you like and median(A)/median(B) will be constant, whereas median(A/B) will likely change. $\endgroup$
    – Hao Ye
    Commented Apr 22, 2014 at 18:35
  • 5
    $\begingroup$ Inspecting a small example of $(A,B)$ pairs might help, such as $(10,1),(10,1),(x,1),(20,2),(20,2)$. If $10\le x\le 20$ then the median $A$ is $x$, the median $B$ is $1$, and the median of $A/B$ is $10$ (no matter what $x$ is). Thus if $x\ne 10$ you have an obvious discrepancy. $\endgroup$
    – whuber
    Commented Apr 22, 2014 at 20:26

3 Answers 3

9
$\begingroup$

This is a property of mathematics, it is actually rare that the order of operations does not matter, e.g. the log of the square root is not the same as the square root of the log (except for a few special cases).

We often focus on some of those special cases where due to operations distributing, associating, and commuting (flashbacks to algebra, oh no!) we can do things in either order. For example to compute a mean we can either add the numbers together then divide the sum by $n$, or we can divide each number by $n$ then sum those values. This is because division (multiplication) distributes over addition. With paired data we have the fact that the mean of the differences is the difference of the means. But these are the rarer cases, not the rule.

So in general you should not expect to get the same result when you do things in a different order, it is also not true that the mean of the ratios is the ratio of the means, so why should it be true for the median?

$\endgroup$
1
  • 8
    $\begingroup$ You mean what the folks over on math.SE call the freshman's dream: $(x+y)^2 = x^2 + y^2$ is not true? :-) $\endgroup$ Commented Apr 22, 2014 at 18:59
5
$\begingroup$

You might find it even more surprising to discover that even with a nice linear operator like expectation, you still have this issue (median is non linear, mean is linear):

$$\text{mean}(A)/\text{mean}(B) \neq \text{mean}(A/B)$$

For example:

 a=1:5
 b=6:10
 mean(a)/mean(b)
[1] 0.375
 mean(a/b)
[1] 0.3543651

But then you should already know that in general $E(XY)\neq E(X)E(Y)$, so perhaps this shouldn't surprise at all!

$\endgroup$
0
$\begingroup$

Erm, for the (obvious?) reason that the fractional representation of a number is not unique, the medians can't be the same.

EDIT: as per Glen's request

The location of the median relies on the ordering of numbers in your set. Suppose you order your numbers from smallest to largest, so you have something like this {1,2,3}. You can maintain the same median if you perform a transformation only if that transformation preserves the ordering. For example, if you add 1 to every single number in your set, location of the median doesn't change: {2, 3, 4}, i.e. it is still located in the second position.

Any linear transformation maintains the order. The maintenance of order is key. That's the "property of mathematics" that's really being referred to below. (And how you define order is also key. Note that order is essentially a notion of distance. 2 is closer to 3 than to 4 because the distance between 2 and 3 is smaller than the distance between 2 and 4). That's why, for positive data, in some instances, it is allowed to apply a log transform of your data - you haven't fundamentally altered the ordering of the numbers, and thus you haven't changed the underlying relationship between your variables. You can do a log transform for say, income data, but you can't do it for inflation data.

If a transformation is not linear, the order is not necessarily maintained. Transforming every number into a fraction is not a linear transformation because the fractional representation of a number is not unique. 1/2 is the same as 2/4. That's why for "large" sets the location of the median changes if you transform your numbers into fractions in the way that you described. For large enough sets, you're eventually going to run into a situation where you have the same fraction in multiple places.If that happens, your set "shrinks" and so the median must change.

$\endgroup$
14
  • 3
    $\begingroup$ Your answer reads more like a comment, and as an explanation it leaves too much unsaid. Could you explain what you mean, please, perhaps with an example? $\endgroup$
    – Glen_b
    Commented Apr 23, 2014 at 3:53
  • $\begingroup$ @Glen_b Done. Hope it helps. $\endgroup$
    – rocinante
    Commented Apr 23, 2014 at 13:08
  • 1
    $\begingroup$ I'm still unsure of what you're getting at with the second sentence of your final paragraph. It's explicitly that which I seek a numerical example of. $\endgroup$
    – Glen_b
    Commented Apr 23, 2014 at 14:07
  • $\begingroup$ @Glen_b A = {1,2,3, 5}B={2,4,6,7} A/B ={1/2,2/4,3/6,5/7} So we went from sets that have 4 distinct elements to a set that has only two distinct elements, all because the fractional representation is not unique. $\endgroup$
    – rocinante
    Commented Apr 23, 2014 at 14:15
  • 1
    $\begingroup$ A={1,2,3,4} and B={8,7,6,5}. A+B = {9,9,9,9}, ... summation isn't unique either. I fear I must be missing something that should be obvious. $\endgroup$
    – Glen_b
    Commented Apr 23, 2014 at 14:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.