For a sample, x, calculate the quantiles, q, corresponding to the cumulative probability values in p. All non-numeric values (NaNs) of x are ignored.
If x is a matrix, compute the quantiles for each column and return them in a matrix, such that the i-th row of q contains the p(i)th quantiles of each column of x.
The optional argument dim determines the dimension along which the percentiles are calculated. If dim is omitted, and x is a vector or matrix, it defaults to 1 (column wise quantiles). In the instance that x is a N-d array, dim defaults to the first dimension whose size greater than unity.
The methods available to calculate sample quantiles are the nine methods used by R (http://www.r-project.org/). The default value is METHOD = 5.
Discontinuous sample quantile methods 1, 2, and 3
- Method 1: Inverse of empirical distribution function.
- Method 2: Similar to method 1 but with averaging at discontinuities.
- Method 3: SAS definition: nearest even order statistic.
Continuous sample quantile methods 4 through 9, where p(k) is the linear interpolation function respecting each methods' representative cdf.
- Method 4: p(k) = k / n. That is, linear interpolation of the empirical cdf.
- Method 5: p(k) = (k - 0.5) / n. That is a piecewise linear function where the knots are the values midway through the steps of the empirical cdf.
- Method 6: p(k) = k / (n + 1).
- Method 7: p(k) = (k - 1) / (n - 1).
- Method 8: p(k) = (k - 1/3) / (n + 1/3). The resulting quantile estimates are approximately median-unbiased regardless of the distribution of x.
- Method 9: p(k) = (k - 3/8) / (n + 1/4). The resulting quantile estimates are approximately unbiased for the expected order statistics if x is normally distributed.
Hyndman and Fan (1996) recommend method 8. Maxima, S, and R (versions prior to 2.0.0) use 7 as their default. Minitab and SPSS use method 6. Matlab uses method 5.
References:
- Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) The New S Language. Wadsworth & Brooks/Cole.
- Hyndman, R. J. and Fan, Y. (1996) Sample quantiles in statistical packages, American Statistician, 50, 361-365.
- R: A Language and Environment for Statistical Computing; http://cran.r-project.org/doc/manuals/fullrefman.pdf.