Quantile


In statistics and probability, quantiles are cut points dividing the range of a probability distribution into continuous intervals with equal probabilities, or dividing the observations in a sample in the same way. There is one fewer quantile than the number of groups created. Thus quartiles are the three cut points that will divide a dataset into four equal-sized groups. Common quantiles have special names: for instance quartile, decile. The groups created are termed halves, thirds, quarters, etc., though sometimes the terms for the quantile are used for the groups created, rather than for the cut points.
-quantiles are values that partition a finite set of values into subsets of equal sizes. There are of the -quantiles, one for each integer satisfying. In some cases the value of a quantile may not be uniquely determined, as can be the case for the median of a uniform probability distribution on a set of even size. Quantiles can also be applied to continuous distributions, providing a way to generalize rank statistics to continuous variables. When the cumulative distribution function of a random variable is known, the -quantiles are the application of the quantile function to the values.

Specialized quantiles

Some -quantiles have special names:
As in the computation of, for example, standard deviation, the estimation of a quantile depends upon whether one is operating with a statistical population or with a sample drawn from it. For a population, of discrete values or for a continuous population density, the -th -quantile is the data value where the cumulative distribution function crosses. That is, is a -th -quantile for a variable if
and
For a finite population of equally probable values indexed from lowest to highest, the -th -quantile of this population can equivalently be computed via the value of. If is not an integer, then round up to the next integer to get the appropriate index; the corresponding data value is the -th -quantile. On the other hand, if is an integer then any number from the data value at that index to the data value of the next can be taken as the quantile, and it is conventional to take the average of those two values.
If, instead of using integers and, the “-quantile” is based on a real number with then replaces in the above formulas. Some software programs regard the minimum and maximum as the 0th and 100th percentile, respectively; however, such terminology is an extension beyond traditional statistics definitions.

Examples

The following two examples use the Nearest Rank definition of quantile with rounding. For an explanation of this definition, see percentiles.

Even-sized population

Consider an ordered population of 10 data values. What are the 4-quantiles of this dataset?
QuartileCalculationResult
Zeroth quartileAlthough not universally accepted, one can also speak of the zeroth quartile. This is the minimum value of the set, so the zeroth quartile in this example would be 3.3
First quartileThe rank of the first quartile is 10× = 2.5, which rounds up to 3, meaning that 3 is the rank in the population at which approximately 1/4 of the values are less than the value of the first quartile. The third value in the population is 7.7
Second quartileThe rank of the second quartile is 10× = 5, which is an integer, while the number of values is an even number, so the average of both the fifth and sixth values is taken—that is /2 = 9, though any value from 8 through to 10 could be taken to be the median.9
Third quartileThe rank of the third quartile is 10× = 7.5, which rounds up to 8. The eighth value in the population is 15.15
Fourth quartileAlthough not universally accepted, one can also speak of the fourth quartile. This is the maximum value of the set, so the fourth quartile in this example would be 20. Under the Nearest Rank definition of quantile, the rank of the fourth quartile is the rank of the biggest number, so the rank of the fourth quartile would be 10.20

So the first, second and third 4-quantiles of the dataset are. If also required, the zeroth quartile is 3 and the fourth quartile is 20.

Odd-sized population

Consider an ordered population of 11 data values. What are the 4-quantiles of this dataset?
QuartileCalculationResult
Zeroth quartileAlthough not universally accepted, one can also speak of the zeroth quartile. This is the minimum value of the set, so the zeroth quartile in this example would be 3.3
First quartileThe first quartile is determined by 11× = 2.75, which rounds up to 3, meaning that 3 is the rank in the population at which approximately 1/4 of the values are less than the value of the first quartile. The third value in the population is 7.7
Second quartileThe second quartile value is determined by 11× = 5.5, which rounds up to 6. Therefore, 6 is the rank in the population at which approximately 2/4 of the values are less than the value of the second quartile. The sixth value in the population is 9.9
Third quartileThe third quartile value for the original example above is determined by 11× = 8.25, which rounds up to 9. The ninth value in the population is 15.15
Fourth quartileAlthough not universally accepted, one can also speak of the fourth quartile. This is the maximum value of the set, so the fourth quartile in this example would be 20. Under the Nearest Rank definition of quantile, the rank of the fourth quartile is the rank of the biggest number, so the rank of the fourth quartile would be 11.20

So the first, second and third 4-quantiles of the dataset are. If also required, the zeroth quartile is 3 and the fourth quartile is 20.

Estimating quantiles from a sample

The asymptotic distribution of -th sample quantile is well-known: it is asymptotically normal around the -th quantile with variance equal to
where is the value of the distribution density at the -th quantile. However, this distribution relies on knowledge of the population distribution; which is equivalent to knowledge of the population quantiles, which we are trying to estimate! Modern statistical packages thus rely on a different technique — or selection of techniques — to estimate the quantiles.
Mathematica, Matlab, R and GNU Octave programming languages include nine sample quantile methods. SAS includes five sample quantile methods, SciPy and Maple both include eight, EViews includes the six piecewise linear functions, Stata includes two, Python includes two, and Microsoft Excel includes two. Mathematica supports an arbitrary parameter for methods that allows for other, non-standard, methods.
In effect, the methods compute, the estimate for the -th -quantile, where, from a sample of size by computing a real valued index. When is an integer, the -th smallest of the values,, is the quantile estimate. Otherwise a rounding or interpolation scheme is used to compute the quantile estimate from,, and. .
The estimate types and interpolation schemes used include:
TypeNotes
R-1, SAS-3, Maple-1Inverse of empirical distribution function.
R-2, SAS-5, Maple-2, StataThe same as R-1, but with averaging at discontinuities.
R-3, SAS-2The observation numbered closest to. Here, indicates rounding to the nearest integer, choosing the even integer in the case of a tie.
R-4, SAS-1, SciPy-, Maple-3Linear interpolation of the empirical distribution function.
R-5, SciPy-, Maple-4Piecewise linear function where the knots are the values midway through the steps of the empirical distribution function.
R-6, Excel, Python, SAS-4, SciPy-, Maple-5, Stata-altdefLinear interpolation of the expectations for the order statistics for the uniform distribution on . That is, it is the linear interpolation between points, where is the probability that the last of randomly drawn values will not exceed the -th smallest of the first randomly drawn values.
R-7, Excel, Python, SciPy-, Maple-6, NumPy, JuliaLinear interpolation of the modes for the order statistics for the uniform distribution on .
R-8, SciPy-, Maple-7Linear interpolation of the approximate medians for order statistics.
R-9, SciPy-, Maple-8The resulting quantile estimates are approximately unbiased for the expected order statistics if is normally distributed.

Notes:
The standard error of a quantile estimate can in general be estimated via the bootstrap. The Maritz–Jarrett method can also be used.

Approximate quantiles from a stream

Computing approximate quantiles from data arriving from a stream can be done efficiently using compressed data structures. The most popular methods are t-digest and KLL. These methods read a stream of values in a continuous fashion and can, at any time, be queried about the approximate value of a specified quantile.
Both algorithms are based on a similar idea: compressing the stream of values by summarizing identical or similar values with a weight. If the stream is made of a repetition of 100 times v1 and 100 times v2, there is no reason to keep a sorted list of 200 elements, it is enough to keep two elements and two counts to be able to recover the quantiles. With more values, these algorithms maintain a trade-off between the number of unique values stored and the precision of the resulting quantiles. Some values may be discarded from the stream and contribute to the weight of a nearby value without changing the quantile results too much. t-digest uses an approach based on k-means clustering to group similar values whereas KLL uses a more sophisticated "compactor" method that leads to better control of the error bounds.
Both methods belong to the family of data sketches that are subsets of Streaming Algorithms with useful properties: t-digest or KLL sketches can be combined. Computing the sketch for a very large vector of values can be split into trivially parallel processes where sketches are computed for partitions of the vector in parallel and merged later.

Discussion

Standardized test results are commonly misinterpreted as a student scoring "in the 80th percentile," for example, as if the 80th percentile is an interval to score "in," which it is not; one can score "at" some percentile, or between two percentiles, but not "in" some percentile. Perhaps by this example it is meant that the student scores between the 80th and 81st percentiles, or "in" the group of students whose score placed them at the 80th percentile.
If a distribution is symmetric, then the median is the mean. But, in general, the median and the mean can differ. For instance, with a random variable that has an exponential distribution, any particular sample of this random variable will have roughly a 63% chance of being less than the mean. This is because the exponential distribution has a long tail for positive values but is zero for negative numbers.
Quantiles are useful measures because they are less susceptible than means to long-tailed distributions and outliers. Empirically, if the data being analyzed are not actually distributed according to an assumed distribution, or if there are other potential sources for outliers that are far removed from the mean, then quantiles may be more useful descriptive statistics than means and other moment-related statistics.
Closely related is the subject of least absolute deviations, a method of regression that is more robust to outliers than is least squares, in which the sum of the absolute value of the observed errors is used in place of the squared error. The connection is that the mean is the single estimate of a distribution that minimizes expected squared error while the median minimizes expected absolute error. Least absolute deviations shares the ability to be relatively insensitive to large deviations in outlying observations, although even better methods of robust regression are available.
The quantiles of a random variable are preserved under increasing transformations, in the sense that, for example, if is the median of a random variable, then is the median of, unless an arbitrary choice has been made from a range of values to specify a particular quantile. Quantiles can also be used in cases where only ordinal data are available.