{
  "id": "median",
  "title": "Median",
  "lang": "en",
  "source_lang": "en",
  "summary": "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.",
  "category": "mathematics",
  "subcategory": "probability-statistics",
  "type": "concept",
  "aliases": [
    "Second quartile",
    "50th percentile",
    "0.5 quantile"
  ],
  "generated_at": "2026-11-02",
  "model": "pro/gpt-6.1-sol",
  "url": "https://aiwiki.page/en/median/",
  "translations": {
    "zh-Hans": {
      "url": "https://aiwiki.page/zh/median/",
      "json": "https://aiwiki.page/zh/median.json"
    }
  },
  "sections": [
    {
      "heading": "",
      "text": "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."
    },
    {
      "heading": "Median of a dataset",
      "text": "Let \\(x_1,\\ldots,x_n\\) be a nonempty dataset of real numbers, and write its ordered values as\n\n\\[x_{(1)}\\le x_{(2)}\\le \\cdots \\le x_{(n)}.\\]\n\nThe parenthesized subscripts indicate order statistics: \\(x_{(k)}\\) is the \\(k\\)-th smallest observation, counting repetitions.\n\nThe conventional sample median is\n\n\\[\\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}\\]\n\nFor example:\n\n- The ordered data \\(2,4,7,9,20\\) have median \\(7\\).\n- The ordered data \\(2,4,7,9\\) have median \\((4+7)/2=5.5\\).\n- The ordered data \\(1,1,1,8,12\\) have median \\(1\\).\n\nA 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.\n\nEven sample sizes and alternative conventions\n\nFor an even-sized sample, every value in the interval\n\n\\[[x_{(n/2)},x_{(n/2+1)}]\\]\n\nhas 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.\n\nFor 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."
    },
    {
      "heading": "Median of a probability distribution",
      "text": "For a real-valued random variable \\(X\\), a number \\(m\\) is a median if\n\n\\[\\Pr(X\\le m)\\ge \\frac12 \\quad\\text{and}\\quad \\Pr(X\\ge m)\\ge \\frac12.\\]\n\nUsing the cumulative distribution function \\(F(x)=\\Pr(X\\le x)\\), this is equivalent to\n\n\\[F(m)\\ge \\frac12, \\qquad F(m^-)\\le \\frac12,\\]\n\nwhere \\(F(m^-)=\\Pr(X<m)\\) is the left-hand limit.\n\nEvery probability distribution on the real line has at least one finite median, but the median need not be unique. For example, if \\(X\\) takes the values \\(0\\) and \\(1\\), each with probability \\(1/2\\), then every number in \\([0,1]\\) is a median.\n\nA commonly used single-valued convention is the lower \\(0.5\\)-quantile,\n\n\\[m_{\\mathrm{lower}}=\\inf\\{x:F(x)\\ge 1/2\\}.\\]\n\nApplied to an empirical distribution with an even number of distinct middle observations, this gives the lower middle observation rather than their average.\n\nIf \\(F\\) is continuous, every median satisfies \\(F(m)=1/2\\). Continuity alone does not guarantee uniqueness: the distribution function may remain equal to \\(1/2\\) across an interval. If it crosses \\(1/2\\) strictly, the median is unique.\n\nSymmetry and existence of a mean\n\nIf a probability distribution is symmetric about a point \\(c\\), then \\(c\\) is a median. When the mean exists, symmetry also places the mean at \\(c\\). Symmetry does not necessarily make the median unique.\n\nThe 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."
    },
    {
      "heading": "Absolute-deviation characterization",
      "text": "The median has an important interpretation in mathematical optimization: it minimizes the sum of absolute deviations,\n\n\\[L(a)=\\sum_{i=1}^{n}|x_i-a|.\\]\n\nFor 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.\n\nThis follows from the slopes of the absolute-value terms. Between observations, moving \\(a\\) 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.\n\nThe corresponding population result is\n\n\\[m\\in\\operatorname*{arg\\,min}_{a\\in\\mathbb R} \\mathbb E|X-a|,\\]\n\nprovided \\(\\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 \\(a\\), so that expression alone no longer distinguishes medians.\n\nThis 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."
    },
    {
      "heading": "Robustness and limitations",
      "text": "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.\n\nFor example, the data\n\n\\[1,2,3,4,100\\]\n\nhave median \\(3\\) and mean \\(22\\). Replacing \\(100\\) by \\(1{,}000{,}000\\) leaves the median at \\(3\\) while greatly increasing the mean.\n\nBreakdown point\n\nThe 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\n\n\\[\\left\\lceil \\frac n2\\right\\rceil.\\]\n\nIts finite-sample replacement breakdown fraction is therefore \\(\\lceil n/2\\rceil/n\\), approaching \\(1/2\\) as the sample size grows. The corresponding fraction for the sample mean is \\(1/n\\).\n\nThis 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.\n\nWhat the median does not describe\n\nA 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.\n\nThe 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.\n\nThe 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."
    },
    {
      "heading": "Transformations",
      "text": "Medians behave naturally under transformations that preserve order. If \\(m\\) is a population median and \\(g\\) is a strictly increasing function, then \\(g(m)\\) is a median of \\(g(X)\\). A strictly decreasing transformation also maps a median to a median, while reversing the ordering.\n\nFor 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:\n\n\\[g\\!\\left(\\frac{x_{(n/2)}+x_{(n/2+1)}}2\\right) \\ne \\frac{g(x_{(n/2)})+g(x_{(n/2+1)})}{2}\\]\n\nin general.\n\nConsequently, taking a conventional sample median and then applying a nonlinear transformation can differ from transforming the data first and then taking their conventional median."
    },
    {
      "heading": "Statistical estimation and uncertainty",
      "text": "The sample median is an estimator of a population median. If independent observations come from the same distribution, the population median \\(m\\) is unique, and a continuous probability density \\(f\\) is positive at \\(m\\), then the sample median is asymptotically normal:\n\n\\[\\sqrt n\\,(\\widetilde X_n-m) \\xrightarrow{d} N\\!\\left(0,\\frac{1}{4f(m)^2}\\right).\\]\n\nIts large-sample standard error is approximately\n\n\\[\\frac{1}{2\\sqrt n\\,f(m)}.\\]\n\nThe density at the median matters: when observations are densely concentrated near \\(m\\), the median is estimated more precisely. If the median is nonunique or the density vanishes there, this approximation may fail.\n\nFor a normal population with variance \\(\\sigma^2\\), the sample median has asymptotic variance\n\n\\[\\frac{\\pi\\sigma^2}{2n},\\]\n\ncompared with \\(\\sigma^2/n\\) for the sample mean. Its asymptotic efficiency relative to the mean under that model is therefore \\(2/\\pi\\), approximately \\(0.637\\). This comparison is specific to the normal model; the median can perform better under other distributions.\n\nA distribution-free confidence interval for a population median can be constructed from order statistics. For independent observations from a continuous distribution with median \\(m\\), the number falling below \\(m\\) has a binomial distribution with parameters \\(n\\) and \\(1/2\\). Suitable binomial tail probabilities determine which ordered observations to use as interval endpoints."
    },
    {
      "heading": "Computation",
      "text": "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.\n\nComparison-based sorting generally takes \\(O(n\\log n)\\) time, whereas selection can find the median in \\(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.\n\nFor 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."
    },
    {
      "heading": "Applications and related concepts",
      "text": "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.\n\nSeveral related constructions extend its role:\n\n- 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.\n- Median absolute deviation: The median of the distances \\(|x_i-\\widetilde x|\\) provides a robust measure of spread.\n- Quantile regression: Median regression estimates a conditional median by minimizing absolute residuals. Other quantiles are obtained through asymmetrically weighted absolute loss.\n- 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.\n- 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."
    }
  ],
  "links": [
    "statistics",
    "real-number",
    "quantile",
    "random-variable",
    "cumulative-distribution-function",
    "probability-distribution",
    "normal-distribution",
    "cauchy-distribution",
    "expected-value",
    "mathematical-optimization",
    "sample-mean",
    "loss-function",
    "mathematical-function",
    "estimator",
    "probability-density-function",
    "standard-error",
    "variance",
    "confidence-interval",
    "binomial-distribution",
    "big-o-notation",
    "median-absolute-deviation"
  ],
  "sources": [],
  "license": "https://creativecommons.org/licenses/by/4.0/"
}