# Betting on a sample from a known distribution

This was an interview question. Given a known distribution, sample a value from it with replacement for many times. Two people A and B bet on the sample with their own guesses, and the one closer to the actual sample value wins. What's your betting strategy?

The interviewer claimed the median value is better than mean. I didn't get it. Can someone explain? Thanks.

• Try a simple example, such as a Bernoulli$(p)$ distribution. When $p\ne 1/2$ the median and mean differ, but it is easy to see which strategy is better and why.
– whuber
May 22 at 12:32

The median minimizes expected absolute distance between observations sampled from the distribution and a single value. That is:

$$\underset{m}{\text{min}}\text{ }\mathbb E\left[ \left\vert X - m\right\vert \right] = \text{median}$$

This is in contrast to the mean, which minimizes expected squared distance.

$$\underset{m}{\text{min}}\text{ }\mathbb E\left[ \left( X - m\right)^2 \right] = \text{mean}$$

I think this is what the interviewer wanted to test if you knew.

• This is the formal derivation I was looking for. Thank you! May 23 at 20:49

The mean is affected by outliers in the distribution, so does not inform us about the mid-point of the distribution. The median is not affected by outliers.

Consider three example distributions and see how the presence of one outlier affects the mean but not the median:

Example Distribution Median Mean
1 [1, 2, 3, 4, 5] 3 3
2 [1, 2, 3, 4, 10] 3 4
3 [1, 2, 3, 4, 20] 3 6

So relating these examples back to your interview question: assume A picks the median, so 50% of the time the sample will be less than A's guess and 50% of the time greater. Therefore, if B picks a different value from A, A's guess must be closer to the sample value at least 50% of the time.

Now assume B picks the mean. In the first case, they pick the same number, so the outcome is a draw. In the second case, A wins 60% of the time, B wins 20% of the time and it's a draw 20% of the time. In the third case, A wins 80% of the time and B wins 20% of the time.

• Re "Therefore, if B picks a different value from A, A's guess must be closer to the sample value at least 50% of the time:" why does this follow? It's not an obvious consequence of the definition of the median, which you haven't quite correctly characterized: it is not always the case that 50% of the time the sample will be less than the median. What you can say is that at least 50% of the time the value will be no greater than the median.
– whuber
May 22 at 12:29
• It makes sense that "50% of the time the sample will be less than A's guess and 50% of the time greater.", while I don't understand why "A's guess must be closer to the sample value at least 50% of the time." How did you derive that? May 23 at 16:28
• @jesse If B picks above A's guess, A is closer to all under-median samples, which are 50% of all possible samples. If B picks below A's guess, A is closer to all over-median samples, which also comprise 50% of all possible samples. No matter what side of A is picked by B, A is closer to at least half of all possible samples, so should be expected to win at least half the time (assuming B doesn't also pick the median). May 23 at 16:57
• @NuclearHoagie Very clear explanation, Thank you! May 23 at 20:49