Why Order Matters for Medians and Quantiles
A sample median describes the center of observed data without being pulled strongly by unusually large or small values. A sample quantile locates a specified fraction of the observations at or below a cutoff. Both are defined by arranging the sample in order, so getting the rank and the convention right matters as much as doing the arithmetic.
The calculations in this tutorial concern a realized sample: the values have already been observed. When the observations are modeled as a random sample, the ordered values and the resulting median or quantile are random statistics. No particular population distribution is needed to calculate them.
For a random sample \(X_1,\ldots,X_n\), the corresponding ordered random variables are written \(X_{(1)}\leq\cdots\leq X_{(n)}\). The notation \(x_{(j)}\) refers to the observed value at rank \(j\); \(X_{(j)}\) refers to the random order statistic before the sample is observed.
Sample Median: Odd and Even Sample Sizes
The conventional sample median is the middle ordered observation when the sample size is odd. When the sample size is even, it is the arithmetic average of the two middle ordered observations. Thus an even-sized sample median need not equal an observation in the data.
This even-sample convention is useful but is not the only mathematically possible way to describe a center. For an even sample, any value between the two middle observations has at least half the observations at or below it and at least half at or above it. The conventional sample median selects the midpoint of that interval. Use this midpoint convention unless a question specifies another one.
Worked Example: Median With an Odd Discrete Sample and Ties
A hypothetical quality audit records the number of surface marks on nine inspected components as \(8,3,5,3,12,5,3,9,5\). Find the sample median and the empirical 30th percentile using the convention defined below.
Method. First sort the observations, retaining every repeated value:
There are \(n=9=2(4)+1\) observations, so the median is the fifth ordered value, \(x_{(5)}=5\). The three observations equal to 3 and the three observations equal to 5 are all counted; ties do not get removed.
For the empirical 30th percentile, set \(p=0.30\). The rank is \(r=\lceil np\rceil=\lceil9(0.30)\rceil=\lceil2.7\rceil=3\), so the empirical quantile is \(x_{(3)}=3\). At the value 3, three of nine observations are at or below it, and \(3/9=0.3333\), which is at least 0.30.
Check and common mistake avoided. The median is the fifth ordered observation, not the average of the third and fourth. For the quantile, the tied values do not change the rank formula; nor should ties be collapsed into one distinct value. The results are median \(5\) and empirical 30th percentile \(3\).
Empirical Quantiles
A quantile convention must specify how a percentage is translated into an ordered observation. This tutorial uses the inverse empirical distribution function convention, also called the nearest-rank convention. It selects an observed value and does not interpolate between two observations.
For example, \(p=0.25\) specifies the empirical 25th percentile, often called the first quartile; \(p=0.50\) specifies the empirical 50th percentile; and \(p=0.75\) specifies the empirical 75th percentile. Under this convention \(Q_n(1)=x_{(n)}\), the sample maximum. The range \(0<p\leq1\) avoids assigning rank zero at \(p=0\); a separate endpoint convention can set the zero quantile to the sample minimum.
For an even sample size, the empirical 50th percentile and the conventional sample median can differ. If \(n=2k\), then \(Q_n(0.50)=x_{(k)}\), while the conventional median is \((x_{(k)}+x_{(k+1)})/2\). This is not a contradiction: the two quantities use different conventions.
| Quantity | Definition for \(n=2k\) | Can it be between observations? |
|---|---|---|
| Empirical 50th percentile | \(x_{(k)}\) | No; it is an observed value |
| Conventional sample median | \((x_{(k)}+x_{(k+1)})/2\) | Yes |
Why the Empirical Quantile Formula Works
The rank formula follows from the definition of the empirical distribution function. Importantly, the argument must allow for ties: several observations can equal the same ordered value, so a quantile is best characterized as the first value at which the empirical distribution function reaches the requested proportion.
For \(0<p\leq1\), let \(r=\lceil np\rceil\). By the definition of the ceiling, \(r\geq np\), while \(r-1<np\).
At \(x_{(r)}\), at least \(r\) observations are at or below that value, so \(F_n(x_{(r)})\geq r/n\geq p\). Ties may make the count larger than \(r\), which does not invalidate the inequality.
If \(x<x_{(r)}\), at most \(r-1\) observations can be at or below \(x\). Therefore \(F_n(x)\leq(r-1)/n<p\). Thus \(x_{(r)}\) is the first value at which the empirical distribution function reaches \(p\), and \(Q_n(p)=x_{(\lceil np\rceil)}\).
This proof also explains why a shortcut based only on the rank proportion can fail as an argument when observations are tied. The first value reaching the required proportion need not have rank \(\lceil np\rceil\): a tie at an earlier rank can make the empirical cumulative proportion jump past \(p\). The formula still selects the correct value because it accounts for the ordered observations and the empirical distribution together.
Worked Example: Even-Sample Median and Empirical Percentiles
A hypothetical maintenance team records repair times, in hours, for eight pieces of equipment: \(14,6,10,6,18,11,10,22\). Find the conventional sample median, the empirical 50th percentile, and the empirical 75th percentile.
Method. Sort the values:
Here \(n=8=2(4)\), so the two middle observations are \(x_{(4)}=10\) and \(x_{(5)}=11\). The conventional sample median is
For \(p=0.50\), the empirical quantile rank is \(\lceil8(0.50)\rceil=\lceil4\rceil=4\), giving \(Q_n(0.50)=x_{(4)}=10\) hours. For \(p=0.75\), the rank is \(\lceil8(0.75)\rceil=\lceil6\rceil=6\), giving \(Q_n(0.75)=x_{(6)}=14\) hours.
Check and common mistake avoided. Exactly four observations are at or below 10, so the empirical distribution there equals \(4/8=0.50\). The 50th percentile under the stated convention is therefore 10, not 10.5. The value 10.5 is the conventional sample median. Confusing those two conventions is the main trap in this calculation.
Calculating Quantiles From Continuous Measurements
When a population is continuous, independent observations from it will be distinct with probability one under the usual continuous-distribution model. However, recorded measurements can still tie because of rounding or limited measurement precision. The order-statistic method applies either way: sort the recorded values, use the specified rank, and do not interpolate unless the problem explicitly requests a different quantile convention.
Worked Example: Median and Quartiles From a Continuous Sample
A hypothetical laboratory records the time, in minutes, required for seven independently selected test runs to complete. The observed times are \(4.0,1.2,8.3,2.8,5.5,3.6,2.1\). Find the sample median and the empirical 25th and 80th percentiles using the inverse empirical distribution convention.
Method. Sort the recorded times:
Since \(n=7=2(3)+1\), the median is the fourth ordered time, \(x_{(4)}=3.6\) minutes.
For the empirical 25th percentile, \(r=\lceil7(0.25)\rceil=\lceil1.75\rceil=2\), so \(Q_n(0.25)=x_{(2)}=2.1\) minutes. For the empirical 80th percentile, \(r=\lceil7(0.80)\rceil=\lceil5.6\rceil=6\), so \(Q_n(0.80)=x_{(6)}=5.5\) minutes.
Check and common mistake avoided. At or below 2.1 minutes there are two of seven observations, a proportion of \(2/7\), which is at least 0.25; at any value below 2.1 the proportion is at most \(1/7\). At or below 5.5 minutes there are six of seven observations, a proportion of \(6/7\), which is at least 0.80; below 5.5 there are at most five of seven, a proportion of \(5/7\). Interpolating between 1.2 and 2.1, or between 4.0 and 5.5, would produce a different convention and is not appropriate here.
Interpretation and Common Exam Traps
The sample median and empirical quantiles are useful summaries because their definitions depend on position in the ordered sample, rather than on adding all values. They are also straightforward to compute for discrete observations, continuous measurements, and samples with ties. Their interpretation should still be stated in context: a sample median repair time of 10.5 hours is a summary of the observed repair times, not automatically the population median.
- Sorting incorrectly or dropping ties. Keep every observation, including repeated values, in the ordered list.
- Using the wrong even-sample convention. The conventional sample median averages the middle pair; the inverse empirical 50th percentile selects the lower middle observation.
- Rounding \(np\) down. The empirical quantile rank is \(\lceil np\rceil\), not \(\lfloor np\rfloor\). If \(np\) is already an integer, its ceiling is that same integer.
- Using a tie-blind proof. With ties, cumulative proportions can jump by more than \(1/n\). Justify the quantile as the first value reaching \(p\), not as the first rank whose rank fraction reaches \(p\).
- Interpolating without being asked. The convention here returns an observed order statistic. Other sample-quantile definitions exist, so identify the convention before calculating.
Check Your Understanding
Use the inverse empirical distribution convention for every requested empirical quantile. Keep the conventional sample median distinct from the empirical 50th percentile when the sample size is even.
- A sensor records \(7,2,4,4,9\). Find the conventional sample median and the empirical 60th percentile. (Answer: median \(4\); empirical 60th percentile \(4\))
- For the observations \(12,3,8,3,15,9\), find the conventional sample median, the empirical 50th percentile, and the empirical \(5/6\) quantile. (Answer: median \(8.5\); empirical 50th percentile \(8\); empirical \(5/6\) quantile \(12\))
- The ordered observations are \(2,2,2,5,5,7,7,7,9,11\). Find the empirical 30th percentile and state the fraction of observations at or below the selected value. (Answer: \(2\); fraction \(3/10=0.3\))
- A set of nine distinct measurements, after sorting, is \(1,2,3,4,5,6,7,8,9\). Find the conventional sample median and the empirical 40th percentile. (Answer: median \(5\); empirical 40th percentile \(4\))
- For the ordered sample \(1,2,3,4,5,6,7,8,9,10,11,12\), find the conventional sample median, the empirical 50th percentile, and the empirical 75th percentile. (Answer: median \(6.5\); empirical 50th percentile \(6\); empirical 75th percentile \(9\))