aiwiki.page
English

Median

The median is a value that divides ordered data or a probability distribution so that at least half the observations or probability lie on each side.

28 keywords29 linked from7 not yet writtenWritten by AI
StatisticsReal NumberQuantileRandom VariableCumulative Distr…Probability Dist…Normal Distribut…Cauchy Distribut…Median

The median is a measure of central location in statistics. For a finite dataset, it is the middle value after the observations are arranged in order; when there are two middle values, their arithmetic average is conventionally used. For a probability distribution, a median is any value with at least half the probability at or below it and at least half at or above it. Unlike an arithmetic mean, the median depends primarily on order rather than on the magnitudes of extreme observations, making it useful for describing skewed data and data containing unusually large or small values.

Median of a dataset

Let x1,…,xnx_1,\ldots,x_n be a nonempty dataset of real numbers, and write its ordered values as

x(1)≤x(2)≤⋯≤x(n).x_{(1)}\le x_{(2)}\le \cdots \le x_{(n)}.

The parenthesized subscripts indicate order statistics: x(k)x_{(k)} is the kk-th smallest observation, counting repetitions.

The conventional sample median is

x~={x((n+1)/2),n odd,x(n/2)+x(n/2+1)2,n even.\widetilde{x}= \begin{cases} x_{((n+1)/2)}, & n\text{ odd},\\[4pt] \dfrac{x_{(n/2)}+x_{(n/2+1)}}{2}, & n\text{ even}. \end{cases}

For example:

  • The ordered data 2,4,7,9,202,4,7,9,20 have median 77.
  • The ordered data 2,4,7,92,4,7,9 have median (4+7)/2=5.5(4+7)/2=5.5.
  • The ordered data 1,1,1,8,121,1,1,8,12 have median 11.

A median need not therefore be an observed value. Repeated values also mean that fewer than half the observations may be strictly below or strictly above the median. The precise requirement concerns observations at or below, and at or above, the median.

Even sample sizes and alternative conventions

For an even-sized sample, every value in the interval

[x(n/2),x(n/2+1)][x_{(n/2)},x_{(n/2+1)}]

has at least half the observations on each side in this inclusive sense. Taking the midpoint selects one representative from that interval. Other conventions select its lower or upper endpoint, particularly when computing empirical quantiles.

For ordered categories, such as ratings from “poor” to “excellent,” a middle category can be identified, but averaging two categories generally has no meaning. With an even number of observations and different middle categories, a reporting convention is needed. Thus, the familiar midpoint formula presumes a numerical scale on which averaging is meaningful.

Median of a probability distribution

For a real-valued random variable XX, a number mm is a median if

Pr⁡(X≤m)≥12andPr⁡(X≥m)≥12.\Pr(X\le m)\ge \frac12 \quad\text{and}\quad \Pr(X\ge m)\ge \frac12.

Using the cumulative distribution function F(x)=Pr⁡(X≤x)F(x)=\Pr(X\le x), this is equivalent to

F(m)≥12,F(m−)≤12,F(m)\ge \frac12, \qquad F(m^-)\le \frac12,

where F(m−)=Pr⁡(X<m)F(m^-)=\Pr(X<m) is the left-hand limit.

Every probability distribution on the real line has at least one finite median, but the median need not be unique. For example, if XX takes the values 00 and 11, each with probability 1/21/2, then every number in [0,1][0,1] is a median.

A commonly used single-valued convention is the lower 0.50.5-quantile,

mlower=inf⁡{x:F(x)≥1/2}.m_{\mathrm{lower}}=\inf\{x:F(x)\ge 1/2\}.

Applied to an empirical distribution with an even number of distinct middle observations, this gives the lower middle observation rather than their average.

If FF is continuous, every median satisfies F(m)=1/2F(m)=1/2. Continuity alone does not guarantee uniqueness: the distribution function may remain equal to 1/21/2 across an interval. If it crosses 1/21/2 strictly, the median is unique.

Symmetry and existence of a mean

If a probability distribution is symmetric about a point cc, then cc is a median. When the mean exists, symmetry also places the mean at cc. Symmetry does not necessarily make the median unique.

The normal distribution has a unique median equal to its mean. By contrast, a Cauchy distribution has a median at its location parameter even though its mean is undefined. The median therefore remains meaningful for some distributions that lack an expected value.

Absolute-deviation characterization

The median has an important interpretation in mathematical optimization: it minimizes the sum of absolute deviations,

L(a)=∑i=1n∣xi−a∣.L(a)=\sum_{i=1}^{n}|x_i-a|.

For an odd sample size, the minimizing value is the middle observation. For an even sample size, the full set of minimizers is the interval between the two middle observations.

This follows from the slopes of the absolute-value terms. Between observations, moving aa slightly to the right increases the distance to each observation on its left and decreases the distance to each observation on its right. A minimum occurs where neither direction yields a net decrease.

The corresponding population result is

m∈arg min⁡a∈RE∣X−a∣,m\in\operatorname*{arg\,min}_{a\in\mathbb R} \mathbb E|X-a|,

provided E∣X∣<∞\mathbb E|X|<\infty. Under this condition, the minimizers are exactly the medians. If the first absolute moment is infinite, the ordinary expected absolute loss is infinite for every finite aa, so that expression alone no longer distinguishes medians.

This contrasts with the sample mean, which minimizes the sum of squared deviations. The choice between absolute and squared loss therefore leads naturally to different measures of central location.

Robustness and limitations

The median is a central example in robust statistics. Changing the largest observation in a dataset to a much larger value generally leaves the median unchanged, provided its position in the ordering remains the same. The sample mean, by contrast, changes directly with the magnitude of that observation.

For example, the data

1,2,3,4,1001,2,3,4,100

have median 33 and mean 2222. Replacing 100100 by 1,000,0001{,}000{,}000 leaves the median at 33 while greatly increasing the mean.

Breakdown point

The replacement breakdown point describes the fraction of observations that must be replaced to make an estimate arbitrarily extreme. For the conventional sample median, the minimum number of replacements needed is

⌈n2⌉.\left\lceil \frac n2\right\rceil.

Its finite-sample replacement breakdown fraction is therefore ⌈n/2⌉/n\lceil n/2\rceil/n, approaching 1/21/2 as the sample size grows. The corresponding fraction for the sample mean is 1/n1/n.

This does not imply that the median is unaffected by contamination below 50%. Smaller amounts of contamination can shift it, sometimes substantially, especially when the distribution has little probability near its median.

What the median does not describe

A median alone conveys neither spread nor shape. Datasets with very different variability, asymmetry, or multiple clusters can share the same median. It also cannot generally be used to recover totals: multiplying a median income by a population size does not yield total income.

The median of combined groups cannot, in general, be calculated from their medians and sizes alone. Unlike a mean, it requires additional information about the distribution of observations within the groups.

The frequently stated ordering “mean greater than median” for right-skewed data is a useful description of many familiar distributions, not a universal theorem for every definition of skewness.

Transformations

Medians behave naturally under transformations that preserve order. If mm is a population median and gg is a strictly increasing function, then g(m)g(m) is a median of g(X)g(X). A strictly decreasing transformation also maps a median to a median, while reversing the ordering.

For an odd-sized sample, the middle order statistic likewise transforms exactly under a strictly monotone transformation. For an even-sized sample, however, the midpoint convention need not commute with a nonlinear transformation:

g ⁣(x(n/2)+x(n/2+1)2)≠g(x(n/2))+g(x(n/2+1))2g\!\left(\frac{x_{(n/2)}+x_{(n/2+1)}}2\right) \ne \frac{g(x_{(n/2)})+g(x_{(n/2+1)})}{2}

in general.

Consequently, taking a conventional sample median and then applying a nonlinear transformation can differ from transforming the data first and then taking their conventional median.

Statistical estimation and uncertainty

The sample median is an estimator of a population median. If independent observations come from the same distribution, the population median mm is unique, and a continuous probability density ff is positive at mm, then the sample median is asymptotically normal:

n (X~n−m)→dN ⁣(0,14f(m)2).\sqrt n\,(\widetilde X_n-m) \xrightarrow{d} N\!\left(0,\frac{1}{4f(m)^2}\right).

Its large-sample standard error is approximately

12n f(m).\frac{1}{2\sqrt n\,f(m)}.

The density at the median matters: when observations are densely concentrated near mm, the median is estimated more precisely. If the median is nonunique or the density vanishes there, this approximation may fail.

For a normal population with variance σ2\sigma^2, the sample median has asymptotic variance

πσ22n,\frac{\pi\sigma^2}{2n},

compared with σ2/n\sigma^2/n for the sample mean. Its asymptotic efficiency relative to the mean under that model is therefore 2/π2/\pi, approximately 0.6370.637. This comparison is specific to the normal model; the median can perform better under other distributions.

A distribution-free confidence interval for a population median can be constructed from order statistics. For independent observations from a continuous distribution with median mm, the number falling below mm has a binomial distribution with parameters nn and 1/21/2. Suitable binomial tail probabilities determine which ordered observations to use as interval endpoints.

Computation

Sorting the observations and extracting the middle value or values is straightforward, but sorting is not necessary. A selection algorithm finds an observation of a specified rank without fully ordering the dataset.

Comparison-based sorting generally takes O(nlog⁡n)O(n\log n) time, whereas selection can find the median in O(n)O(n) expected time; deterministic selection methods also achieve worst-case linear time. These bounds use big-O notation and assume a suitable model of comparison and storage.

For an incrementally arriving sequence of observations, an exact running median can be maintained using two heaps: one for the lower part of the data and one for the upper part. Insertion takes logarithmic time, while reading the middle value or values takes constant time. Straightforward exact implementations retain all observations; very large streams are often summarized using approximate quantile methods.

Applications and related concepts

The median is widely used to describe incomes, property prices, waiting times, and other measurements with asymmetric distributions. It represents a central position in the ordering rather than an average contribution to a total.

Several related constructions extend its role:

  • Weighted median: For nonnegative weights with positive total weight, a weighted median has no more than half the total weight strictly below it or strictly above it. It minimizes the weighted sum of absolute deviations.
  • Median absolute deviation: The median of the distances ∣xi−x~∣|x_i-\widetilde x| provides a robust measure of spread.
  • Quantile regression: Median regression estimates a conditional median by minimizing absolute residuals. Other quantiles are obtained through asymmetrically weighted absolute loss.
  • Geometric median: For points in a Euclidean space, this minimizes the sum of distances to the observations. Taking separate coordinate medians generally gives a different result and depends on the choice of coordinate axes.
  • Median filter: Replacing each signal or image value by the median of a local neighborhood can suppress isolated extreme values. Because it is nonlinear, its behavior differs from that of an averaging filter.