quantile
Compute quantile values.
Syntax
q = quantile(x)
q = quantile(x,p)
q = quantile(x,p,dim)
q = quantile(x,p,dim,method)
Inputs
- x
- Data sample.
- p
- Probabilities for which to compute quantile values.
- dim
- Dimension on which to perform the calculation.
- method
- Quantiles are computed by defining an inverse distribution function
from the empirical sample. Let n equal the sample size in what follows.
The available options are:
- '1'
- The inverse cumulative distribution function, which is a left continuous step function.
- '2'
- The inverse cumulative distribution function, using average sample values at the discontinuities.
- '3'
- Select samples with index k nearest to n * p, choosing the even index when two are equally close (SAS method).
- '4'
- Interpolate sample k using p(k) = k / n (Parzen method).
- '5'
- Interpolate sample k using p(k) = (k - 0.5) / n (Hazen method).
- '6'
- Interpolate sample k using p(k) = k / (n + 1) (Weibull method).
- '7'
- Interpolate sample k using p(k) = (k - 1) / (n - 1) (Gumbel method).
- '8'
- Interpolate sample k using p(k) = (k - 1/3) / (n + 1/3) (median unbiased method).
- '9'
- Interpolate sample k using p(k) = (k - 3/8) / (n + 1/4) (normal unbiased method).
Outputs
- q
- Quantiles for each entry in p.
Examples
Matrix case operating by row:
x = [0.69 0.58 0.55 0.60 0.71 0.30 0.67 0.46 0.64 0.78 0.85 0.76 0.59 0.38 0.90 0.81 0.53 0.73 0.62 0.43;
0.84 0.75 0.57 0.36 0.55 0.64 0.73 0.68 0.60 0.62 0.78 0.49 0.46 0.27 0.42 0.81 0.66 0.89 0.52 0.71];
p = [0.0, 0.2, 0.4, 0.6, 0.8, 1.0];
q = quantile(x, p, 2, 5)
q = [Matrix] 2 x 6
0.30000 0.49500 0.59500 0.68000 0.77000 0.90000
0.27000 0.47500 0.58500 0.67000 0.76500 0.89000
Comments
When x is a matrix, q will be a matrix with length(p) values in dimension dim. When x and p are vectors, q will have the same orientation as p.
R. J. Hyndman, Y. Fan, "Sample Quantiles in Statistical Packages" American Statistician, Vol. 50, pp. 361–365, 1996.