Main Content

Quantiles and Percentiles

This example explains how MATLAB®功能定量ileandprctilecompute quantiles and percentiles.

Theprctilefunction calculates the percentiles in a similar way to how定量ilecalculates quantiles. These steps in the computation of quantiles are also true for percentiles, given the fact that, for the same data sample, the quantile at the valueQis the same as the percentile at the valueP= 100*Q.

  1. 定量ileinitially assigns the sorted values inXto the (0.5/n), (1.5/n), ..., ([n– 0.5]/n) quantiles. For example:

    • For a data vector of six elements such as {6, 3, 2, 10, 8, 1}, the sorted elements {1, 2, 3, 6, 8, 10} respectively correspond to the (0.5/6), (1.5/6), (2.5/6), (3.5/6), (4.5/6), and (5.5/6) quantiles.

    • For a data vector of five elements such as {2, 10, 5, 9, 13}, the sorted elements {2, 5, 9, 10, 13} respectively correspond to the 0.1, 0.3, 0.5, 0.7, and 0.9 quantiles.

    This figure illustrates this approach for data vectorX= {2, 10, 5, 9, 13}. The first observation corresponds to the cumulative probability 1/5 = 0.2, the second observation corresponds to the cumulative probability 2/5 = 0.4, and so on. The step function in this figure shows these cumulative probabilities.定量ileinstead places the observations in midpoints, such that the first corresponds to 0.5/5 = 0.1, the second corresponds to 1.5/5 = 0.3, and so on, and then connects these midpoints. The red lines in the figure connect the midpoints.

    Assigning Observations to Quantiles

    Plot showing the relationship between observations and quantiles

    By switching the axes, as in the next figure, you can see the values of the variableXthat correspond to thep定量iles.

    Quantiles ofX

    Plot showing quantiles of data vector x

  2. 定量ilefinds any quantiles between the data values using linear interpolation.

    Linear interpolationuses linear polynomials to approximate a function f(x) and construct new data points within the range of a known set of data points. Algebraically, given the data points (x1,y1) and (x2,y2), wherey1= f(x1) andy2= f(x2), linear interpolation findsy= f(x) for a givenxbetweenx1andx2as

    y = f ( x ) = y 1 + ( x x 1 ) ( x 2 x 1 ) ( y 2 y 1 ) .

    Similarly, if the 1.5/n定量ile isy1.5/nand the 2.5/n定量ile isy2.5/n, then linear interpolation finds the 2.3/n定量iley2.3/nas

    y 2.3 n = y 1.5 n + ( 2.3 n 1.5 n ) ( 2.5 n 1.5 n ) ( y 2.5 n y 1.5 n ) .

  3. 定量ileassigns the minimum and maximum values ofXto the quantiles for probabilities less than (0.5/n) and greater than ([n–0.5]/n), respectively.

References

[1] Langford, E. “Quartiles in Elementary Statistics”,Journal of Statistics Education. Vol. 14, No. 3, 2006.

See Also

||