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 be a nonempty dataset of real numbers, and write its ordered values as
The parenthesized subscripts indicate order statistics: is the -th smallest observation, counting repetitions.
The conventional sample median is
For example:
- The ordered data have median .
- The ordered data have median .
- The ordered data have median .
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
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 , a number is a median if
Using the cumulative distribution function , this is equivalent to
where 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 takes the values and , each with probability , then every number in is a median.
A commonly used single-valued convention is the lower -quantile,
Applied to an empirical distribution with an even number of distinct middle observations, this gives the lower middle observation rather than their average.
If is continuous, every median satisfies . Continuity alone does not guarantee uniqueness: the distribution function may remain equal to across an interval. If it crosses strictly, the median is unique.
Symmetry and existence of a mean
If a probability distribution is symmetric about a point , then is a median. When the mean exists, symmetry also places the mean at . 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,
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 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
provided . 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 , 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
have median and mean . Replacing by leaves the median at 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
Its finite-sample replacement breakdown fraction is therefore , approaching as the sample size grows. The corresponding fraction for the sample mean is .
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 is a population median and is a strictly increasing function, then is a median of . 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:
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 is unique, and a continuous probability density is positive at , then the sample median is asymptotically normal:
Its large-sample standard error is approximately
The density at the median matters: when observations are densely concentrated near , 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 , the sample median has asymptotic variance
compared with for the sample mean. Its asymptotic efficiency relative to the mean under that model is therefore , approximately . 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 , the number falling below has a binomial distribution with parameters and . 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 time, whereas selection can find the median in 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 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.