maths.freeStatistics & Probability › Describing data › Median

Median

The median of a set of numbers is the value separating the higher half from the lower half of a data sample, a population, or a probability distribution. For a data set, it may be thought of as the "middle" value.

Median

The median of a set of numbers is the value separating the higher half from the lower half of a data sample, a population, or a probability distribution. For a data set, it may be thought of as the "middle" value. The basic feature of the median in describing data compared to the mean (often simply described as the "average") is that it is not skewed by a small proportion of extreme values, and therefore provides a better representation of the center. Median income, for example, may be a better way to describe the center of the income distribution because increases in the largest incomes alone have no effect on the median. For this reason, the median is of central importance in robust statistics. Median is a 2-quantile; it is the value that partitions a set into two equal parts.

Finite set of numbers

The median of a finite list of numbers is the middle number when the numbers are arranged in order from smallest to greatest.

If the data set has an odd number of observations, the middle one is selected (after arranging in ascending order). For example, the following list of seven numbers,

1, 3, 3, 6, 7, 8, 9

has the median of 6, which is the fourth value.

If the data set has an even number of observations, there is no distinct middle value and the median is usually defined to be the arithmetic mean of the two middle values. For example, this data set of 8 numbers

1, 2, 3, 4, 5, 6, 8, 9

has a median value of 4.5, that is \((4 + 5)/2\). (In more technical terms, this interprets the median as the fully trimmed mid-range).

In general, with this convention, the median can be defined as follows: For a data set \(x\) of \(n\) elements, ordered from smallest to greatest,

if \(n\) is odd, \(\operatorname{med}(x) = x_{(n + 1)/ 2}\)if \(n\) is even, \(\operatorname{med}(x) = \frac{x_{(n/2)} + x_{((n/2)+1)}}{2}\)

Definition and notation

Formally, a median of a population is any value such that at least half of the population is less than or equal to the proposed median and at least half is greater than or equal to the proposed median. As seen above, medians may not be unique. If each set contains more than half the population, then some of the population is exactly equal to the unique median.

The median is well-defined for any ordered (one-dimensional) data and is independent of any distance metric. The median can thus be applied to student grades that are ranked but not numerical (e.g. working out a median grade when student test scores are graded from F to A). The result might be halfway between grades if there is an even number of students; for an odd number students, one specific grade is determined as the median.

A geometric median, on the other hand, is defined in any number of dimensions. A related concept, in which the outcome is forced to correspond to a member of the sample, is the medoid.

There is no widely accepted standard notation for the median, but some authors represent the median of a variable x as med(x), , as μ1/2, or as M. In any of these cases, the use of these or other symbols for the median needs to be explicitly defined when they are introduced.

The median is a special case of other ways of summarizing the typical values associated with a statistical distribution: it is the 2nd quartile, 5th decile, and 50th percentile.

Uses

The median can be used as a measure of location when one attaches reduced importance to extreme values, typically because a distribution is skewed, extreme values are not known, or outliers are untrustworthy, i.e., may be measurement or transcription errors.

For example, consider the multiset

1, 2, 2, 2, 3, 14.

The median is 2 in this case, as is the mode, and it might be seen as a better indication of the center than the arithmetic mean of 4, which is larger than all but one of the values. However, the widely cited empirical relationship that the mean is shifted "further into the tail" of a distribution than the median is not generally true. At most, one can say that the two statistics cannot be "too far" apart; see § Inequality relating means and medians below.

As a median is based on the middle data in a set, it is not necessary to know the value of extreme results in order to calculate it. For example, in a psychology test investigating the time needed to solve a problem, if a small number of people failed to solve the problem at all in the given time a median can still be calculated.

Because the median is simple to understand and easy to calculate, while also a robust approximation to the mean, the median is a popular summary statistic in descriptive statistics. In this context, there are several choices for a measure of variability: the range, the interquartile range, the mean absolute deviation, and the median absolute deviation.

For practical purposes, different measures of location and dispersion are often compared on the basis of how well the corresponding population values can be estimated from a sample of data. The median, estimated using the sample median, has good properties in this regard. While it is not usually optimal if a given population distribution is assumed, its properties are always reasonably good. For example, a comparison of the efficiency of candidate estimators shows that the sample mean is more statistically efficient when, and only when, data is uncontaminated by data from heavy-tailed distributions or from mixtures of distributions. Even then, the median has a 64% efficiency compared to the minimum-variance mean (for large normal samples), which is to say the variance of the median will be ~50% greater than the variance of the mean.

Probability distributions

A median of a real-valued random variable \(X\) is a real number \(m\) that satisfies \[\operatorname{P}(Xm) \leq \frac{1}{2}\] or, equivalently with the complementary events, \[\operatorname{P}(X\geq m) \geq \frac{1}{2} \quad\text{and}\quad \operatorname{P}(X\leq m) \geq \frac{1}{2}\,.\] Such an \(m\) always exists, but needs not be uniquely determined. An equivalent phrasing uses the cumulative distribution function \(F\colon\, \R\to\R\) of \(X\colon\) \[\lim_{x\to m-} F(x) \leq \frac{1}{2} \leq F(m)\] (cf. the drawing in the definition of expected value for arbitrary real-valued random variables).

Note that this definition does not require X to have an absolutely continuous distribution (which has a probability density function f), nor does it require a discrete one. In the former case, the inequalities can be upgraded to equality: a median satisfies \[\operatorname{P}(X \leq m) = \int_{-\infty}^m{f(x)\, dx} = \frac{1}{2}\] and \[\operatorname{P}(X \geq m) = \int_m^{\infty}{f(x)\, dx} = \frac{1}{2}\,.\]

Any probability distribution on the real number set \(\R\) has at least one median, but in pathological cases there may be more than one median: if F is constant 1/2 on an interval (so that f = 0 there), then any value of that interval is a median.

Medians of particular distributions

The medians of certain types of distributions can be easily calculated from their parameters; furthermore, they exist even for some distributions lacking a well-defined mean, such as the Cauchy distribution:

  • The median of a symmetric unimodal distribution coincides with the mode.
  • The median of a symmetric distribution which possesses a mean μ also takes the value μ.
    • The median of a normal distribution with mean μ and variance σ is μ. In fact, for a normal distribution, mean = median = mode.
    • The median of a uniform distribution in the interval [ab] is (a + b) / 2, which is also the mean.
  • The median of a Cauchy distribution with location parameter x0 and scale parameter y is x0, the location parameter.
  • The median of a power law distribution x, with exponent a > 1 is 2xmin, where xmin is the minimum value for which the power law holds.
  • The median of an exponential distribution with rate parameter λ is the natural logarithm of 2 divided by the rate parameter: λln 2.
  • The median of a Weibull distribution with shape parameter k and scale parameter λ is λ(ln 2).

Optimality property

The mean absolute error of a real variable m with respect to the random variable X is \[\operatorname{E}\left[\left|X-m\right|\right]\] Provided that the probability distribution of X is such that the above expectation exists, then m is a median of X if and only if m is a minimizer of the mean absolute error with respect to X. In particular, if m is a sample median, then it minimizes the arithmetic mean of the absolute deviations. Note, however, that in cases where the sample contains an even number of elements, this minimizer is not unique.

This optimization-based definition of the median is useful in statistical data-analysis, for example, in k-medians clustering.

Inequality relating means and medians

If the distribution has finite variance, then the distance between the median \(\tilde{X}\) and the mean \(\bar{X}\) is bounded by one standard deviation.

This bound was proved by Book and Sher in 1979 for discrete samples, and more generally by Page and Murty in 1982. In a comment on a subsequent proof by O'Cinneide, Mallows in 1991 presented a compact proof that uses Jensen's inequality twice, as follows. Using |·| for the absolute value, we have

\[\begin{aligned} \left|\mu - m\right| = \left|\operatorname{E}(X - m)\right| & \leq \operatorname{E}\left(\left|X - m \right|\right) \\[2ex] & \leq \operatorname{E}\left(\left|X - \mu\right|\right) \\[1ex] & \leq \sqrt{\operatorname{E}\left({\left(X - \mu\right)}^2\right)} = \sigma. \end{aligned}\]

The first and third inequalities come from Jensen's inequality applied to the absolute-value function and the square function, which are each convex. The second inequality comes from the fact that a median minimizes the absolute deviation function \(a \mapsto \operatorname{E}[|X-a|]\).

Mallows's proof can be generalized to obtain a multivariate version of the inequality simply by replacing the absolute value with a norm: \[\left\|\mu - m\right\| \leq \sqrt{ \operatorname{E}\left({\left\|X - \mu\right\|}^2\right) } = \sqrt{ \operatorname{trace}\left(\operatorname{var}(X)\right) }\]

where m is a spatial median, that is, a minimizer of the function \(a \mapsto \operatorname{E}(\|X-a\|).\,\) The spatial median is unique when the data-set's dimension is two or more.

An alternative proof uses the one-sided Chebyshev inequality; it appears in an inequality on location and scale parameters. This formula also follows directly from Cantelli's inequality.

Mean, median, and skew

A typical heuristic is that positively skewed distributions have mean > median. This is true for all members of the Pearson distribution family. However this is not always true. For example, the Weibull distribution family has members with positive mean, but mean < median. Violations of the rule are particularly common for discrete distributions. For example, any Poisson distribution has positive skew, but its mean < median whenever \(\mu \bmod 1>\ln 2\). See for a proof sketch.

When the distribution has a monotonically decreasing probability density, the median is less than the mean, as shown in the figure.

Jensen's inequality for medians

Jensen's inequality states that for any random variable X with a finite expectation E[X] and for any convex function f

\[f(\operatorname{E}(x)) \le \operatorname{E}( f(x) )\]

This inequality generalizes to the median as well. We say a function f: RR is a C function if, for any t,

\[f^{-1}\left( \,(-\infty, t]\, \right) = \{ x \in \Reals \mid f(x) \le t \}\] is a closed interval (allowing the degenerate cases of a single point or an empty set). Every convex function is a C function, but the reverse does not hold. If f is a C function, then

\[f(\operatorname{med}[X]) \le \operatorname{med}[ f(X)]\]

If the medians are not unique, the statement holds for the corresponding suprema.

Efficient computation of the sample median

Even though comparison-sorting n items requires Ω(n log n) operations, selection algorithms can compute the kth-smallest of n items with only Θ(n) operations. This includes the median, which is the ⁠n/2⁠th order statistic (or for an even number of samples, the arithmetic mean of the two middle order statistics).

Selection algorithms still have the downside of requiring Ω(n) memory, that is, they need to have the full sample (or a linear-sized portion of it) in memory. Because this, as well as the linear time requirement, can be prohibitive, several estimation procedures for the median have been developed. A simple one is the median of three rule, which estimates the median as the median of a three-element subsample; this is commonly used as a subroutine in the quicksort sorting algorithm, which uses an estimate of its input's median. A more robust estimator is Tukey's ninther, which is the median of three rule applied with limited recursion: if A is the sample laid out as an array, and

med3(A) = med(A[1], A[⁠n/2⁠], A[n]),

then

ninther(A) = med(med3(A[1 ... ⁠1/3⁠n]), med3(A[⁠1/3⁠n ... ⁠2/3⁠n]), med3(A[⁠2/3⁠n ... n]))

The remedian is an estimator for the median that requires linear time but sub-linear memory, operating in a single pass over the sample.

Sampling distribution

The distributions of both the sample mean and the sample median were determined by Laplace. The distribution of the sample median from a population with a density function \(f(x)\) is asymptotically normal with mean \(m\) and variance

\[\frac{ 1 }{ 4n f( m )^2 }\]

where \(m\) is the median of \(f(x)\) and \(n\) is the sample size:

\[\text{Sample median} \sim \mathcal{N}{\left(\mu{=}m, \, \sigma^2{=}\frac{1}{ 4n f(m)^2}\right)}\]

A modern proof follows below. Laplace's result is now understood as a special case of the asymptotic distribution of arbitrary quantiles.

For normal samples, the density is \(f(m) = 1 / \sqrt{2\pi\sigma^2}\), thus for large samples the variance of the median equals \(({\pi}/{2}) \cdot(\sigma^2/n).\) (See also section #Efficiency below.)

Estimation of variance from sample data

The value of \((2 f(x))^{-2}\), the asymptotic value of \(n^{-1/2} (\nu - m)\) where \(\nu\) is the population median, has been studied by several authors. The standard "delete one" jackknife method produces inconsistent results. An alternative, the "delete k" method, where \(k\) grows with the sample size has been shown to be asymptotically consistent. This method may be computationally expensive for large data sets. A bootstrap estimate is known to be consistent, but converges very slowly (order of \(n^{-\frac{1}{4}}\)). Other methods have been proposed but their behavior may differ between large and small samples.

Efficiency

The efficiency of the sample median, measured as the ratio of the variance of the mean to the variance of the median, depends on the sample size and on the underlying population distribution. For a sample of size \(N = 2n + 1\) from the normal distribution, the efficiency for large N is

\[\frac{2}{\pi} \frac{N+2}{N}\]

The efficiency tends to \(\frac{2}{\pi}\) as \(N\) tends to infinity.

In other words, the relative variance of the median will be \(\pi/2 \approx 1.57\), or 57% greater than the variance of the mean: the relative standard error of the median will be \((\pi/2)^\frac{1}{2} \approx 1.25\), or 25% greater than the standard error of the mean, \(\sigma/\sqrt{n}\) (see also section #Sampling distribution above.).

ఇప్పుడుమీరు ఏ గణనపరికరం ఈ వర్తిస్తుంది, కానీ దానిలోని భాగాలు పోబుల్ చేయదగినవి. క్రింద ఒకటి ప్రయత్నించండి లేదా మీ స్వంత టైపు చేయండి.

మీ సొంత పని ఉంచుకోండి

మీరు ఏ పాఠం నేర్చుకున్నారో, ఆ విషయం గురించి ఒక రిపోర్టులో మీరు తీసుకున్న సమస్యలను, మీ సమస్యలను ఒక స్థలంలో పరిష్కరించిన సమస్యలను, మీరు ఈ పేజీ గురించి అడగవచ్చు.

నమోదు చేసుకోండి ప్రవేశించు

ఇక్కడ వుపయోగించిన చిహ్నాలు

మొదటి శతాబ్దంలోని క్రైస్తవులు కూడా అదే విధంగా భావించారు.

ప్రశ్నలు

Mean or median, which should I use?

Median when the data have outliers or a long tail (incomes, house prices); mean when the data are roughly symmetric and you want every value to count. Report both if they disagree. The gap is itself information.

What does a p-value actually say?

The probability of seeing data at least this extreme if the null hypothesis were true. It is not the probability that the null hypothesis is true.

Why divide by n − 1 for the sample variance?

The sample mean sits closer to the sample than the true mean does, so squared deviations from it are slightly too small on average; dividing by n − 1 instead of n corrects the bias.

ఈ పేజీలోని భాగాలు సవరింపుగా ఉన్నాయి Wikipedia (CC BY-SA 4.0). ఇక్కడ సమీకరించబడి మరియు తిరిగి ఉద్భవింపచేయబడిన తప్పులు మావి.

ఇంకా Statistics & Probability