More generally, one can consider the quantile function for any distribution. This is defined for real variables between zero and one and is mathematically the inverse of the cumulative distribution function.
Some software programs (including Microsoft Excel) regard the minimum and maximum as the 0th and 100th percentile, respectively; however, such terminology is an extension beyond traditional statistics definitions. For an infinite population, the kth quantile is the data value where the cumulative distribution function is equal to k/q. For a finite N sample size, calculate —if this is not an integer, then round up to the next integer to get the appropriate sample number (assuming samples ordered by increasing value); if it is an integer, then any value from the value of that sample number to the value of the next can be taken as the quantile, and it is conventional (though arbitrary) to take the average of those two values (see Estimating the quantiles ).
More formally: the kth "q"-quantile of the population parameter X can be defined as the value "x" such that:
If, instead of using integers k and q, the p-quantile is based on a real number p with 0<p<1, then this becomes: The p-quantile of the distribution of a random variable X can be defined as the value(s) x such that:
The motivation for this method is that the first quartile should divide the data between the bottom quarter and top three-quarters. Ideally, this would mean 2.5 of the samples are below the first quartile and 7.5 are above, which in turn means that the third data sample is "split in two", making the third sample part of both the first and second quarters of data, so the quartile boundary is right at that sample.
If a distribution is symmetrical, then the median is the mean (so long as the latter exists). But, in general, the median and the mean 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 to long-tailed distributions and outliers.
Empirically, if the data you are analyzing are not actually distributed according to your assumed distribution, or if you have 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 generally preserved under increasing transformations, in the sense that, for example, if m is the median of a random variable X, then 2m is the median of 2X, 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 is available.
Let N be the number of non-missing values of the sample population, and let represent the ordered values of the sample population such that is the smallest value, etc. For the kth q-quantile, let .Empirical distribution function : is the integer part of and is the fractional partEmpirical distribution function with averaging : is the integer part of and is the fractional partWeighted average : is the integer part of and is the fractional part. This method is used, for example, in the PERCENTILE function of Microsoft Excel.Sample number closest to (N-1)·p+1 : is the integer part of and is the fractional part