Skip to content

Sample quantile

Estimate a population quantile from sorted observations, compare empirical inversion with type 7 interpolation, and understand ties, endpoints and sparse tails.

A sample quantile is a value calculated from observed data to estimate a chosen population quantile. The probability level specifies the part of the distribution of interest; the calculation rule specifies how to turn a finite sample into that estimate. A sample 90th percentile is therefore incomplete without its convention.

This matters when two risk reports use the same loss history but disagree about its upper tail. One may select an observed loss; the other may interpolate between two losses. Both can be reproducible calculations without being the same statistic, and neither makes the population threshold known.

Five losses, two answers

Suppose a desk has five synthetic one-day portfolio losses, in USD, already sorted:

x(1),…,x(5)=1,2,3,4,8.x_{(1)},\ldots,x_{(5)}=1,2,3,4,8.

Here x(k)x_{(k)} is the kkth order statistic. Positive values mean losses; a high probability level looks toward larger losses. Replacing losses with signed returns changes which tail answers a downside-risk question.

The empirical inverse-CDF rule, called type 1 in R, puts equal probability on each observation and selects
Q^inv(p)=inf⁡{x:F^n(x)≥p}=x(⌈np⌉),0<p≤1,\widehat Q_{\mathrm{inv}}(p) =\inf\{x:\widehat F_n(x)\ge p\} =x_{(\lceil np\rceil)},\qquad 0<p\le1,

where F^n(x)\widehat F_n(x) is the observed fraction at or below xx. For p=0.9p=0.9, the required rank is ⌈5(0.9)⌉=5\lceil5(0.9)\rceil=5, giving USD 8. The empirical CDF is 0.8 immediately below 8 and reaches 1 at 8; this is its first crossing of 0.9.

R's type 7 rule instead joins the points with probability coordinates (k−1)/(n−1)(k-1)/(n-1) by straight lines. For n≥2n\ge2 and 0≤p<10\le p<1, calculate
h=1+(n−1)p,j=⌊h⌋,g=h−j,Q^7(p)=(1−g)x(j)+gx(j+1).\begin{aligned} h&=1+(n-1)p,\\ j&=\lfloor h\rfloor,\\ g&=h-j,\\ \widehat Q_7(p)&=(1-g)x_{(j)}+g x_{(j+1)}. \end{aligned}

Set Q^7(1)=x(n)\widehat Q_7(1)=x_{(n)} separately. Here h=4.6h=4.6, so the estimate lies 60% of the way from the fourth observation to the fifth:

Q^7(0.9)=0.4(4)+0.6(8)=6.4 USD.\widehat Q_7(0.9)=0.4(4)+0.6(8)=6.4\text{ USD}.
Probability levelEmpirical inverse, USDType 7 interpolation, USD
0.5033
0.7544
0.9086.4
Synthetic losses USD 1, 2, 3, 4 and 8 give an empirical inverse 90th percentile of USD 8 and a type 7 interpolated estimate of USD 6.4. Only four of five losses, or 80%, are at or below USD 6.4.
Synthetic losses USD 1, 2, 3, 4 and 8 give an empirical inverse 90th percentile of USD 8 and a type 7 interpolated estimate of USD 6.4. Only four of five losses, or 80%, are at or below USD 6.4.
Original synthetic one-day loss example. The dashed segments select observed order statistics; hollow left endpoints are excluded and filled right endpoints included. The solid line interpolates. At probability zero the minimum is used as an endpoint extension.
Interpolation does not create an extra observation. At USD 6.4, only four of the five recorded losses are at or below the estimate: 80%, not 90%. Type 7 estimates a population threshold using a different rule; it does not invert this sample's step CDF. The R documentation lists nine algorithms and uses type 7 as its default. Choosing a convention explicitly makes the result reproducible; a default is not a claim that one convention is universally best.

Ties, medians and endpoints

Keep repeated observations. For the sample 1,2,2,41,2,2,4, both rules give a median of 2, yet 75% of observations are at or below 2. A jump can cross a probability level without equalling it. Rearranging equal observations cannot change either value-based quantile calculation; averaging their ranks is a separate ranking operation.

A broader quantile definition allows any qq satisfying F(q−)≤p≤F(q)F(q-)\le p\le F(q). Such a quantile can be nonunique. For the empirical distribution of 1,2,3,41,2,3,4 at p=0.5p=0.5, every value in [2,3][2,3] qualifies. The lower inverse selects 2; type 7 gives the usual averaged sample median, 2.5. Naming the rule resolves the ambiguity.

Type 7 returns the minimum at p=0p=0 and maximum at p=1p=1; with one observation it returns that observation throughout. The inverse formula above also gives the maximum at p=1p=1, but its literal infimum over all real xx at p=0p=0 is negative infinity. Software commonly extends it to return the sample minimum there. That computational endpoint convention says nothing about the population's smallest or largest possible outcome.

Precision in the calculation is not precision in the estimate

If five observations are independent draws from the same continuous population with F(q0.9)=0.9F(q_{0.9})=0.9, the probability that all five lie below the true 90th percentile is
0.95=0.59049.0.9^5=0.59049.

Thus even the largest observed loss can sit below the population threshold. This probability concerns repeated samples under the stated model; it is not a 59.049% posterior probability that this particular desk's unknown threshold exceeds USD 8. Interpolating to more decimal places cannot supply the unobserved tail information. Serial dependence, a changing market regime and selective data collection add further concerns.

For a historical Value-at-Risk estimate, report the loss definition and horizon, sample window and size, quantile algorithm, and missing-data or weighting treatment. The two formulas here use equally weighted observations. A sample quantile is a threshold estimate, rather than a maximum-loss forecast or a tail-average loss.
For the theory behind the ranks, Order Statistics and Sample Quantiles derives their sampling distributions and the large-sample behaviour of the median. The Empirical CDF, Glivenko–Cantelli, and QQ-Plots develops the step distribution used in the inverse rule. Both offer public previews; complete lessons require membership.

Sources

  • Larry Wasserman, All of Statistics: A Concise Course in Statistical Inference, Chapter 7, §7.1 (empirical distribution function) and §7.2, Example 7.14 (sample quantiles through the generalised inverse).
  • R stats documentation: Sample Quantiles, algorithm definitions, type 7 default and endpoint behaviour.
  • Rob J. Hyndman and Yanan Fan, “Sample Quantiles in Statistical Packages”, The American Statistician 50(4), 361–365 (1996); author's page includes subsequent corrections and discussion of ties.
Last updated
  • sample quantile
  • order statistics
  • empirical cdf
  • interpolation
  • tail risk
← Back to the glossaryBack to top ↑