Tutorials › Statistical Theory I - Probability and Distribution Theory › The Finite-Sample Distribution of the Sample Median

Order Statistics and Sample Extremes · Tutorial 459 of 994

The Finite-Sample Distribution of the Sample Median

Learn how the sample-size parity and the convention for even-sample medians determine their exact finite-sample distributions.

Intermediate 11 min read

What You'll Learn

  • Define the sample median for odd and even sample sizes using order statistics
  • Derive the odd-sample median CDF and, for continuous samples, its density
  • Obtain the even-sample median law from the joint density of consecutive order statistics
  • Calculate median probabilities and moments for uniform and exponential samples
  • Work out the finite-sample distribution and moments of a median from a Bernoulli sample
  • Recognize why ties and the even-sample median convention matter

Why the Median Has a Finite-Sample Distribution

The sample median is an order statistic, so its distribution depends on the sample size and, in an important way, on whether that size is odd or even. With an odd sample there is one middle observation. With an even sample, the usual convention averages the two middle observations. The resulting statistic is generally not itself an order statistic, so its distribution requires a separate calculation.

The distinction matters for probabilities and moments, not just notation. Even when observations have a simple distribution, the finite-sample median can have a different shape and spread from an individual observation. We derive both cases from order-statistic laws and then calculate exact examples.

Definition: Let \(X_1,\ldots,X_n\) be an IID sample with distribution function \(F\), and write its order statistics as \(X_{(1)}\le \cdots \le X_{(n)}\). If \(n=2r+1\), the sample median is \(M=X_{(r+1)}\). If \(n=2r\), we use the conventional averaged median \(M=\{X_{(r)}+X_{(r+1)}\}/2\). For even \(n\), this is a specified convention; another convention, such as taking the lower middle observation, defines a different statistic.

Odd Sample Sizes: The Middle Order Statistic

For any real \(x\), the event \(X_{(r+1)}\le x\) occurs exactly when at least \(r+1\) of the \(2r+1\) observations are at most \(x\). The number of observations at most \(x\) has a binomial distribution with success probability \(F(x)\). This counting argument applies whether or not \(F\) is continuous, and so includes distributions with atoms and ties.

Theorem: If \(n=2r+1\), then for any distribution function \(F\), $$ P(M\le x)=\sum_{k=r+1}^{2r+1}\binom{2r+1}{k}F(x)^k\{1-F(x)\}^{2r+1-k}. $$ If, in addition, \(F\) is absolutely continuous with density \(f\), then \(M\) has density $$ f_M(x)=\frac{(2r+1)!}{r!\,r!}F(x)^r\{1-F(x)\}^r f(x). $$

The CDF formula follows by summing the probabilities that exactly \(k\) observations fall at or below \(x\), for \(k=r+1,\ldots,2r+1\). To obtain the density, put \(p=F(x)\) and differentiate the binomial tail with respect to \(p\). In this derivative, the positive part at index \(k\) cancels the negative part at index \(k-1\); the uncancelled boundary term is the positive part at \(k=r+1\). Thus, for \(0\le p\le1\),

$$ \frac{d}{dp}\sum_{k=r+1}^{2r+1}\binom{2r+1}{k}p^k(1-p)^{2r+1-k} = \frac{(2r+1)!}{r!\,r!}p^r(1-p)^r. $$

The chain rule gives \(dp/dx=f(x)\) almost everywhere, yielding the stated density. It integrates to one: substituting \(p=F(x)\), or using the probability integral transform for an absolutely continuous \(F\), gives the beta integral with parameters \(r+1,r+1\). This completes the derivation.

Worked Example: A Five-Observation Uniform Median

Let \(X_1,\ldots,X_5\) be IID Uniform\((0,1)\), and let \(M=X_{(3)}\). Find \(P(M\le 0.4)\), the density, and the variance.

At \(x=0.4\), at least three observations must be at most \(0.4\). Therefore $$ P(M\le 0.4)=\sum_{k=3}^{5}\binom{5}{k}(0.4)^k(0.6)^{5-k}. $$

The three terms are \(10(0.064)(0.36)=0.2304\), \(5(0.0256)(0.6)=0.0768\), and \(0.01024\). Their sum is \(0.31744\).

Here \(F(x)=x\) and \(f(x)=1\) on \(0<x<1\), so $$ f_M(x)=30x^2(1-x)^2,\qquad 0<x<1. $$

By symmetry around \(1/2\), \(E[M]=1/2\). The variance is $$ \operatorname{Var}(M)=30\int_0^1(x-\tfrac12)^2x^2(1-x)^2\,dx =30\left(\frac{1}{840}\right)=\frac{1}{28}. $$ For the integral, \(\int_0^1x^2(1-x)^2\,dx=1/30\), and the corresponding normalized density \(30x^2(1-x)^2\) is symmetric with variance \(1/28\); equivalently, direct expansion of the displayed integrand gives \(1/840\). Thus the median has mean \(1/2\) and variance \(1/28\), smaller than the variance \(1/12\) of one Uniform\((0,1)\) observation.

Even Sample Sizes: Averaging the Two Middle Values

For \(n=2r\), the averaged median is not an order statistic. For a continuous sample, its distribution can be obtained from the joint density of \(X_{(r)}\) and \(X_{(r+1)}\). This consecutive-order-statistic density has no factor for observations between the two selected values, since there are none.

Theorem: Suppose \(n=2r\), and the IID observations have an absolutely continuous distribution with density \(f\) and CDF \(F\). For \(u<v\), the joint density of the two middle order statistics is $$ f_{X_{(r)},X_{(r+1)}}(u,v)= \frac{(2r)!}{(r-1)!(r-1)!} F(u)^{r-1}\{1-F(v)\}^{r-1}f(u)f(v). $$ Consequently, the CDF of the averaged median is $$ P(M\le m)= \int\!\!\int_{\substack{u<v\\u+v\le 2m}} \frac{(2r)!}{(r-1)!(r-1)!} F(u)^{r-1}\{1-F(v)\}^{r-1}f(u)f(v)\,dv\,du. $$

To see the joint-density coefficient and factors, place one observation near \(u\) and a different observation near \(v\). Of the remaining \(2r-2\) observations, exactly \(r-1\) must lie below \(u\) and \(r-1\) above \(v\). There are \((2r)!/\{(r-1)!(r-1)!\}\) ways to assign these roles. Independence gives the factors \(F(u)^{r-1}\), \(\{1-F(v)\}^{r-1}\), and \(f(u)f(v)\). The median event is \(u+v\le 2m\), which gives the CDF integral.

Where a density for \(M\) is desired, changing variables from \((u,v)\) to \((u,m)\), with \(v=2m-u\), gives the Jacobian factor \(2\). The resulting density, wherever the integral is defined, is $$ f_M(m)= \frac{2(2r)!}{\{(r-1)!\}^2} \int_{u<m}F(u)^{r-1}\{1-F(2m-u)\}^{r-1}f(u)f(2m-u)\,du. $$ The density factors ensure that only points in the support contribute.

Worked Example: The Median of Two Exponential Observations

Let \(X_1,X_2\) be IID exponential with rate \(\lambda>0\). For \(n=2\), the averaged median is \(M=(X_1+X_2)/2\). Find its density, its mean and variance, and \(P(M\le 0.5)\) when \(\lambda=2\).

The joint density of the two observations is \(\lambda^2e^{-\lambda(x_1+x_2)}\) for positive \(x_1,x_2\). Equivalently, the density of the two ordered observations is \(2\lambda^2e^{-\lambda(u+v)}\) for \(0<u<v\). At a fixed \(m>0\), set \(v=2m-u\); the constraint \(u<v\) becomes \(0<u<m\). Including the Jacobian \(2\), $$ f_M(m)=2\int_0^m 2\lambda^2 e^{-2\lambda m}\,du =4\lambda^2m e^{-2\lambda m},\qquad m>0. $$

This is a gamma density with shape \(2\) and rate \(2\lambda\), as can also be checked by integrating it. Its mean is \(2/(2\lambda)=1/\lambda\), and its variance is \(2/(2\lambda)^2=1/(2\lambda^2)\). Its CDF is $$ P(M\le m)=1-e^{-2\lambda m}(1+2\lambda m),\qquad m\ge0, $$ as follows by integrating the density. For \(\lambda=2\) and \(m=0.5\), this probability is \(1-3e^{-2}\), approximately \(0.5940\).

Discrete Samples: Ties and Median Probabilities

For a discrete distribution, the odd-sample CDF formula remains valid, but the median need not have a density. It may have point masses, and ties can occur. For even \(n\), the averaged median can also take values between support points of the observations. Its law must be calculated using the chosen averaging convention, rather than by treating it as one of the two middle order statistics.

Worked Example: An Averaged Median from a Bernoulli Sample

Let \(X_1,\ldots,X_4\) be IID Bernoulli\((p)\), with \(P(X_i=1)=p\), and use \(M=\{X_{(2)}+X_{(3)}\}/2\). Find the full distribution and its moments when \(p=0.3\).

Let \(K\) be the number of ones. If \(K\le1\), the two middle observations are both zero and \(M=0\). If \(K=2\), they are zero and one, giving \(M=1/2\). If \(K\ge3\), both are one and \(M=1\). Hence $$ P(M=0)=(1-p)^4+4p(1-p)^3,\quad P(M=\tfrac12)=6p^2(1-p)^2,\quad P(M=1)=4p^3(1-p)+p^4. $$

At \(p=0.3\), these probabilities are \(0.7^4+4(0.3)(0.7)^3=0.6517\), \(6(0.3)^2(0.7)^2=0.2646\), and \(4(0.3)^3(0.7)+(0.3)^4=0.0837\). They sum to \(1\). Therefore $$ E[M]=\tfrac12(0.2646)+0.0837=0.216, \qquad E[M^2]=\tfrac14(0.2646)+0.0837=0.14985, $$ and $$ \operatorname{Var}(M)=E[M^2]-\{E[M]\}^2 =0.14985-(0.216)^2=0.103194. $$ In particular, the probability at \(1/2\) is a genuine point mass created by the averaged-median convention; it is not an observation value in the Bernoulli support.

Common Pitfall and Why the Exact Law Matters

A common mistake is to use the odd-sample formula for an even sample, or to call \(X_{(r)}\) the median when the specified statistic is the average of \(X_{(r)}\) and \(X_{(r+1)}\). For example, in the Bernoulli calculation, the event \(M\le1/2\) includes outcomes with exactly two successes, and \(M=1/2\) has positive probability. The lower middle observation is zero in those cases, so it cannot represent the averaged median.

Another pitfall is to assume that the median has a density just because the observations are continuous, or conversely to assume that every even-sample median must be an observed value. For continuous observations the averaged median has a density obtained from the joint law; for discrete observations it can have atoms at averages of support points. The finite-sample law makes these distinctions explicit and provides the exact probabilities and moments needed to describe the statistic before using any large-sample approximation.

Key takeaway: For odd \(n\), the sample median is a single order statistic and its CDF is a binomial tail in \(F(x)\). For even \(n\), under the averaged convention, its law comes from the joint distribution of the two middle order statistics. Discreteness and ties must be handled under the stated convention.

Check Your Understanding

Use the order-statistic definition and the even-sample convention stated above.

  1. For an IID sample of size \(7\), express the CDF of the sample median in terms of \(F(x)\).
  2. Why does the odd-sample CDF formula remain valid when \(F\) has point masses?
  3. For \(n=2\), identify the region in the \((u,v)\)-plane corresponding to the event that the averaged median is at most \(m\).
  4. For four Bernoulli observations, what value does the averaged median take when exactly two observations are one, and what is the probability of that case?
  5. Explain why the lower middle order statistic and the averaged median need not have the same distribution for an even sample.