103
$\begingroup$

It is a known fact that median is resistant to outliers. If that is the case, when and why would we use the mean in the first place?

One thing I can think of perhaps is to understand the presence of outliers i.e. if the median is far from the mean, then the distribution is skewed and perhaps the data needs to be examined to decide what is to be done with the outliers. Are there any other uses?

$\endgroup$
6
  • 16
    $\begingroup$ Regarding the first question a quick side note: Mean in statistics is just the first moment of a population, while median is not. Seeking to use CLT, law of large numbers, etc. you are again linked to the existence of finite moments. Though taking for example Cauchy distribution: median exists, while mean doesn't ;) $\endgroup$ Commented Aug 13, 2011 at 13:12
  • 5
    $\begingroup$ @Dmitrij That is a deep and insightful answer. Why don't you elaborate on it in a reply? $\endgroup$
    – whuber
    Commented Aug 13, 2011 at 14:36
  • $\begingroup$ If you didn't use the mean you'd hurt its feelings? (Sorry, couldn't resist.) $\endgroup$ Commented Aug 15, 2011 at 1:21
  • 4
    $\begingroup$ @Daniel R Hicks: And that's quite mean, is it? (Sorry, couldn't resist as well). $\endgroup$ Commented Aug 15, 2011 at 10:08
  • 3
    $\begingroup$ This question is much more interesting than the usual, "How come we don't just always use robust algorithms?" question, but may have the same underlying thinking that "robust == magical" and if we just used robust methods, we wouldn't have to examine our data, understand it, or worry about different kinds of accuracy issues, since they're "robust". Still, +1. $\endgroup$
    – Wayne
    Commented Aug 15, 2011 at 17:48

9 Answers 9

140
$\begingroup$

In a sense, the mean is used because it is sensitive to the data. If the distribution happens to be symmetric and the tails are about like the normal distribution, the mean is a very efficient summary of central tendency. The median, while being robust and well-defined for any continuous distribution, is only $\frac{2}{\pi}$ as efficient as the mean if the data happened to come from a normal distribution. It is this relative inefficiency of the median that keeps us from using it even more than we do. The relative inefficiency translates into a minor absolute inefficiency as the sample size gets large, so for large $n$ we can be more guilt-free about using the median.

It is interesting to note that for a measure of variation (spread, dispersion), there is a very robust estimator that is 0.98 as efficient as the standard deviation, namely Gini's mean difference. This is the mean absolute difference between any two observations. [You have to multiply the sample standard deviation by a constant to estimate the same quantity estimated by Gini's mean difference.] An efficient measure of central tendency is the Hodges-Lehmann estimator, i.e., the median of all pairwise means. We would use it more if its interpretation were simpler.

$\endgroup$
9
  • 16
    $\begingroup$ +1 for mentioning Hodges-Lehmann estimator of central tendency. In many respects it is in-between of mean and median. If only it were easy to calculate in large sample it'd be more popular than mean or median as a measure of location, I think. $\endgroup$
    – ttnphns
    Commented Aug 13, 2011 at 17:07
  • $\begingroup$ BTW, @Frank, do you know which theoretical sampling distribution Hodges-Lehmann centre follows? I don't - and I take interest. $\endgroup$
    – ttnphns
    Commented Aug 13, 2011 at 17:25
  • 17
    $\begingroup$ Thanks for the comment. A one-liner in R can compute it efficiently up to N=5000: w <- outer(x, x, '+'); median(w[row(w) >= col(w)])/2. A trivial C, Fortran, or Ratfor program could be called by R to make it blazing fast. The ICSNP package in R has a fairly efficient implementation with its hl.loc function. For N=5000 it was 2.66 times faster than the above code (total time 1.5 sec.). It would be nice to also get an confidence interval efficiently. $\endgroup$ Commented Aug 13, 2011 at 17:29
  • $\begingroup$ @FrankHarrel what can you say about $S_n$ and $Q_n$ estimators for standard deviation? Which constant should I use for estimation of $\sigma$ using Gini's mean difference for non-normal distributions? I could not find the papers that describe the procedure of this constant's calculation in open access sources...Also I did not found any information about robustness of Gini's mean difference, could you give an idea where to search it? $\endgroup$ Commented Jan 20, 2016 at 14:23
  • 1
    $\begingroup$ We are talking about dispersion measures so comparison of models is not at issue (and don't confuse with "Gini's Index"). Gini's mean difference is an absolute measure. It is easier to interpret than the other measures. The fact that you would need to compute a different constant for every distribution tells me that we don't want to use the constant. $\endgroup$ Commented Jan 21, 2016 at 13:52
46
$\begingroup$

Lots of great answers already, but, taking a step back and getting a little more basic, I'd say it's because the answer you get depends on the question you ask. The mean and median answer different questions - sometimes one is appropriate, sometimes the other.

It's simple to say that the median should be used when there are outliers, or for skewed distributions, or whatever. But that's not always the case. Take income - nearly always reported with median, and usually that's right. But if you are looking at the spending power of a whole community, it may not be right. And in some cases, even the mode might be best (esp. if the data are grouped).

$\endgroup$
3
  • 11
    $\begingroup$ +1 for the obvious point that nobody else seemed to address: they are different concepts and answer different questions. Also in many instances much is lost by condensing the entire distribution into one summary number, so sometimes they both do a lousy job. $\endgroup$ Commented Aug 15, 2011 at 18:38
  • $\begingroup$ sorry for the late reply. Why is income always reported with median? you said that it's not always about whether there are outliers or not. also, why is it not right to trust the median when looking at the spending power of a whole community? also, you said "The mean and median answer different questions", can you please tell me what questions they answer? $\endgroup$
    – floyd
    Commented Sep 2, 2022 at 15:13
  • 1
    $\begingroup$ That's because the median is more representative of the population. The mean can be thrown off by one trillionaire. Not so for the median. $\endgroup$ Commented Sep 28, 2022 at 22:47
26
$\begingroup$

When a value is garbage for us we call it "outlier" and want analysis be robust to it (and prefer median); when that same value is attractive we call it "extreme" and want analysis be sensitive to it (and prefer mean). Dialectics ...

Mean reacts equally to a shift of value irrespective to where in the distribution the shift takes place. For example, in 1 2 3 4 5 you may increase any value by 2 - the increase of mean will be the same. Median's reaction is less "consistent": add 2 to data points 4 or 5, and median won't increase; but add 2 to point 2 - so that the shift is over the median, and the median changes dramatically (greatly than mean will change).

Mean is always exactly located. Median is not; for example, in set 1 2 3 4 any value between 2 and 3 can be called median. Thus, analyses based on medians are not always unique solution.

Mean is a locus of minimal sum-of-squared-deviations. Many optimization tasks based on linear algebra (including famous OLS regression) minimize this squared error and therefore imply concept of mean. Median a locus of minimal sum-of-absolute-deviations. Optimization techniques to minimize such error are non-linear and are more complex / poorly known.

$\endgroup$
5
  • 3
    $\begingroup$ +1 I have a little concern that the first paragraph might be misunderstood as implying outlier detection is entirely a subjective process. I don't think you mean to imply that, though. $\endgroup$
    – whuber
    Commented Aug 13, 2011 at 14:33
  • 9
    $\begingroup$ +1 | I think the first sentence implies that the application of outlier detection is entirely subjective and therefore I vote for keep as is. $\endgroup$
    – John
    Commented Aug 13, 2011 at 15:18
  • 3
    $\begingroup$ I meant that outliar detection is stringent procedure with subjective philosophical or moral roots $\endgroup$
    – ttnphns
    Commented Aug 13, 2011 at 16:59
  • $\begingroup$ Quizz: "Optimization techniques to minimize such error are non-linear and are more complex / poorly known." In what decade was this statement last true? $\endgroup$
    – user603
    Commented Aug 14, 2011 at 15:00
  • 2
    $\begingroup$ @ttnphns, thought so. Some outliers are really outliars short for outright liars :) $\endgroup$
    – mpiktas
    Commented Aug 16, 2011 at 10:14
16
$\begingroup$

There are a lot of answers to this question. Here's one that you probably won't see elsewhere so I'm including it here because I believe it's pertinent to the topic. People often believe that because the median is considered a robust measure with respect to outliers that it's also robust to most everything. In fact, it's also considered robust to bias in skewed distributions. These two robust properties of the median are often taught together. One might note that underlying skewed distributions also tend to generate small samples that look like they have outliers and conventional wisdom is that one use medians in such situations.

#function to generate random values from a skewed distribution
rexg <- function (n, m, sig, tau) {
    rexp(n, rate = 1/tau) + rnorm(n, mean = m, sd = sig)
    }

(just a demonstration that this is skewed and the basic shape)

hist(rexg(1e4, 0, 1, 1))

plot

Now, let's see what happens if we sample from this distribution various sample sizes and calculate median and mean to see what the differences between them are.

#generate values with various n's
N <- 1e4
ns <- 2:30
y <- sapply(ns, function(x) mean(apply(matrix(rexg(x*N, 0, 1, 1), 
            ncol = N), 2, median)))
plot(ns,y, type = 'l', ylim = c(0.85, 1.03), col = 'red') 
y <- sapply(ns, function(x) mean(colMeans(matrix(rexg(x*N, 0, 1, 
                                    1), ncol = N))))
lines(ns,y)

plot2

As can be seen from the above plot the median (in red) is much more sensitive to the n than the mean. This is contrary to some conventional wisdom regarding using medians with low ns, especially if the distribution might be skewed. And, it reinforces the point that the mean is a known value while the median is sensitive to other properties, one if which being the n.

This analysis is similar to Miller, J. (1988). A warning about median reaction time. Journal of Experimental Psychology: Human Perception and Performance, 14(3):539–543.

REVISION

Upon thinking about the skew issue I considered that the impact on the median might just be because in small samples you have a greater probability that the median is in the tail of the distribution, whereas the mean will almost always be weighted by values closer to the mode. Therefore, perhaps if one was just sampling with a probability of outliers then maybe the same results would occur.

So I thought about situations where outliers may occur and experimenters may attempt to eliminate them.

If outliers happened consistently, such as one in every single sampling of data, then medians are robust against the effect of this outlier and the conventional story about the use of medians holds.

But that's not usually how things go.

One might find an outlier in very few cells of an experiment and decide to use median instead of mean in this case. Again, the median is more robust but it's actual impact is relatively small because there are very few outliers. This would definitely be a more common case then the one above but the effect of using a median would probably be so small that it wouldn't matter much.

Perhaps more commonly outliers might be a random component of the data. For example, the true mean and standard deviation of the population may be about 0 but there's a percentage of the time we sample from an outlier population where the mean is 3. Consider the following simulation, where just such a population is sampled varying the sample size.

# generate n samples N times with an outp probability 
# of an outlier.
rout <- function (n, N, outp) {
    outPos <- sample(0:1,n*N, replace = TRUE, 
              prob = c(1-outp, outp))
    numOutliers <- sum(outPos)
    y <- matrix( rnorm(N*n), ncol = N )
    y[which(outPos==1)] <- rnorm(numOutliers, 4)
    return(y)
    }

outp <- 0.1
N <- 1e4
ns <- 3:30
yMed <- sapply(ns, function(x) mean(apply(rout(x,N,outp), 2, 
               median)))
var(yMed)
yM <- sapply(ns, function(x) mean(colMeans(rout(x, N, outp))))
var(yM)
plot(ns,yMed, type = 'l', ylim = range(c(yMed,yM)), ylab = 'Y', 
        xlab = 'n', col = 'red') 
lines(ns,yM)

results

The median is in red and mean in black. This is a similar finding to that of a skewed distribution.

In a relatively practical example of the use of medians to avoid the effects of outliers one can come up with situations where the estimate is affected by n much more when the median is used than when the mean is used.

$\endgroup$
11
  • $\begingroup$ Nice example, but it really depends on the distribution. If you use a normal distribution or an uniform distribution the graph is very different, with the two lines being superimposed. It's the exponential distribution that produces the difference. $\endgroup$
    – nico
    Commented Aug 13, 2011 at 11:55
  • 1
    $\begingroup$ -1 This answer confuses "sensitivity" with "bias." $\endgroup$
    – whuber
    Commented Aug 13, 2011 at 14:30
  • 4
    $\begingroup$ Much better; I've removed the downvote. But I'm intrigued by the new explanation: could you point out some source--a text, paper, or Web site--that actually makes the claim "[the median] is also considered robust to bias in skewed distributions" and explains what that might mean? I haven't come across such a claim before and am not sure what it's really saying. $\endgroup$
    – whuber
    Commented Aug 14, 2011 at 23:04
  • 4
    $\begingroup$ It's more folk knowledge for dealing with reaction times (known to be skewed) in psychology research. I put in a reference to a paper that refutes the folk wisdom in psychology (that I feel bad about not referencing earlier). $\endgroup$
    – John
    Commented Aug 15, 2011 at 4:26
  • 3
    $\begingroup$ BTW, in spite of the Miller (1988) paper people still use median reaction times in studies with probability manipulations where the conditions have different numbers of samples and the lower one is usually rather small. $\endgroup$
    – John
    Commented Aug 15, 2011 at 4:32
12
$\begingroup$
  • From the mean it's easy to calculate the sum over all items, e.g. if you know the average income of the population and the size of the population, you can immediately calculate the total income of the entire population.

  • The mean is straightforward to calculate in O(n) time complexity. Calculating the median in linear time is possible but requires more thought. The obvious solution requiring sorting has worse (O(n log n)) time complexity.

And I speculate that there is another reason for the mean being more popular than the median:

  • The mean is taught to more persons at school and it's probably taught before teaching the median
$\endgroup$
2
  • $\begingroup$ For your time complexity point, it depends on how the values are stored. If the values are already sorted, then it is certainly possible to calculate median in O(1) worst case time complexity. $\endgroup$
    – luiscubal
    Commented Aug 13, 2011 at 15:58
  • $\begingroup$ I agree - its applicability in calculations like sums is one of the main advantages of the mean. While I often prefer the median when the goal is to describe something, we often use the mean when it is an input to another calculation. $\endgroup$
    – Jonathan
    Commented Nov 23, 2011 at 20:13
5
$\begingroup$

"It is a known that median is resistant to outliers. If that is the case, when and why would we use the mean in the first place?"

In cases one knows there are no outliers, for example when one knows the data-generating process (for example in mathematical statistics).

One should point out the trivial, that, these two quantities (mean and median) are actually not measuring the same thing and that most users ask for the former when what they really ought to be interested in the latter (this point is well illustrated by the median-based Wilcoxon tests which are more readily interpreted than the t-tests).

Then, there are the cases where for some happenstance reason or another, some regulation imposes the use of the mean.

$\endgroup$
0
2
$\begingroup$

If the concern is over the presence of outliers, there are some straight-forward ways to check your data.

Outliers, almost by definition, come into our data when something changes either in the process generating the data or in the process collecting the data. i.e. the data ceases to be homogeneous. If your data is not homogeneous then neither the mean nor the median make much sense, since you are trying to estimate the central tendency of two separate data sets that have been mixed together.

The best method to ensure homogeneity is to examine the data-generating and -collection processes to ensure that all of your data is coming from a single set of processes. Nothing beats a little brain-power, here.

As a secondary check, you can turn to one of several statistical tests: chi-squared, Dixon's Q-test, Grubb's test or the control chart / process behavior chart (typically X-bar R or XmR). My experience is that, when your data can be ordered as it was collected, the process behavior charts are better at detecting outliers than the outlier tests. This use for the charts may be somewhat controversial, but I believe it is entirely consistent with Shewhart's original intent and it is a use that is explicitly advocated by Donald Wheeler. Whether you use the outliers tests or the process behavior charts, remember that a detected "outlier" is merely signalling potential non-homogeneity that needs to be further examined. It rarely makes sense to throw out data points if you don't have some explanation for why they were outliers.

If you are using R, the outliers package provides the outliers tests, and for process behavior charts there is the qcc, IQCC and qAnalyst. I have a personal preference for the usage and output of the qcc package.

$\endgroup$
2
$\begingroup$

When might you want the mean?

Examples from finance:

  • Bond returns:
    • The median bond return will generally be a few percentage points.
    • The mean bond return might be low or high depending on the default rate and recovery in default. The median will ignore all this!
    • Good luck explaining to your investors, "I know our fund is down 40% this year because almost half are bonds went bust with no recovery, but our median bond returned 1%!"
  • Venture capital returns:
    • Same thing in reverse. The median VC or angel investment is a bust, and all the return comes from a few winners! (Side note/warning: estimates of venture capital or private equity returns are highly problematic... be careful!)

When forming a diversified portfolio, deciding what to invest in and how much, the mean and covariance of returns are likely to factor prominently into your optimization problem.

$\endgroup$
5
  • $\begingroup$ Agreed, but it seems that mean or median is not the focus in any of these situations: it's rather that totals can be the key quantities. Naturally that implies in turn that means would be better summaries than medians. But granted that median bond return might be a silly answer, but does anyone propose it? $\endgroup$
    – Nick Cox
    Commented Aug 12, 2016 at 18:02
  • $\begingroup$ @NickCox Two comments. (1) That the median bond return is silly is the point! There's great theory in these answers, but I thought an extremely simple example might add some color. To quote Frank's answer, "the mean is used because it is sensitive to the data" and portfolio returns gives a simple, understandable situation where you'd want that. (2) The distinction between caring about the "total" vs. caring about the "mean" can get rather nebulous. "Should I invest in a hedge fund?" To answer that, perhaps I'd like to know, "what's the mean return of hedge funds?" $\endgroup$ Commented Aug 12, 2016 at 18:24
  • 2
    $\begingroup$ (1) I agree, as said; my question is only whether the median is mentioned seriously in teaching or research literature for this purpose. (2) I don't think my point is nebulous; it's a simple question of what comes first, i.e. is of primary interest practically. I see headlines "gang jailed for a total of 200 years" and I know why they're printed, but it's an odd way of summarizing nevertheless. Conversely, 200 killed in a series of disasters is primary, rather than 5 disasters with a mean of 40 killed in each. The (small) issue is choosing which summary statement is most suitable. $\endgroup$
    – Nick Cox
    Commented Aug 12, 2016 at 18:32
  • $\begingroup$ @NickCox Point taken. I agree you care about the total of your own investments. When forming a portfolio and deciding portfolio weights on specific securities though, you're going to care properties of that security's return. I'm not going to buy ALL the municipal bonds, I don't directly care about the total, but I do care about what's the average return on a municipal bond? What are the risk/return properties if I were to add a few to my portfolio? $\endgroup$ Commented Aug 12, 2016 at 18:41
  • $\begingroup$ Agreed. That's the territory here. $\endgroup$
    – Nick Cox
    Commented Aug 12, 2016 at 18:42
0
$\begingroup$

We use the mean more than the median because it is additive, in two senses. (I am surprised that in 11 years, no one has really said this!)

  1. If data on a population is broken down into data about men and data about women, then for example: \begin{align} \text{average overall height =} &\text{average height for men} * \text{fraction of men}\\ & + \text{average height of women} * \text{fraction of women} \end{align} So means are additive over merged populations: the mean of a large population is the average of means over subpopulations, weighted by their sizes. No analog holds for medians.

  2. If we have data on paired variables for a single population, then for example: \begin{align} \text{average income after tax =} &\text{ average income before tax}\\ & - \text{average taxes paid} \end{align} So means are additive over paired variables; the mean of a sum or difference is the sum or difference of the means. No analog holds for medians.

  3. If we have data broken down by day of the week, then for example: \begin{align} \text{average sales for a week = } &\text{average sales for a Sunday} + \\ &\cdots + \text{average sales for a Saturday} \end{align} This could be considered an example of either of the above situations. Again, no analog holds for medians.

Because means are additive, you can calculate a mean from smaller pieces of data. But to calculate a median usually requires having one comprehensive data source for everything. This is a much bigger practical issue than a little loss of efficiency in a summary statistic.

The geometric mean also has these same properties, with addition replaced by multiplication, additive replaced by multiplicative, etc.

In general, the only statistics with both of these aggregative properties are transformed versions of the mean, of the form $f^{-1}(E[f(X)])$, for some increasing function $f$. E.g., the geometric mean is the case with $f(x)=\ln(x)$, $f^{-1}(x)=e^x$. The general result can be seen as a corollary of the Morgenstern-von Neumann theorem on expected utility.

$\endgroup$

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.