NAG Library Function Document
nag_double_quantiles (g01amc) finds specified quantiles from a vector of unsorted data.
||nag_double_quantiles (Integer n,
const double q,
A quantile is a value which divides a frequency distribution such that there is a given proportion of data values below the quantile. For example, the median of a dataset is the quantile because half the values are less than or equal to it; and the quantile is the th percentile.
nag_double_quantiles (g01amc) uses a modified version of Singleton's ‘median-of-three’ Quicksort algorithm (Singleton (1969)
) to determine specified quantiles of a vector of real values. The input vector is partially sorted, as far as is required to compute desired quantiles; for a single quantile, this is much faster than sorting the entire vector. Where necessary, linear interpolation is also carried out to return the values of quantiles which lie between two data points.
Singleton R C (1969) An efficient algorithm for sorting with minimal storage: Algorithm 347 Comm. ACM 12 185–187
n – IntegerInput
the number of elements in the input vector rv
rv[n] – doubleInput/Output
On entry: the vector whose quantiles are to be determined.
: the order of the elements in rv
is not, in general, preserved.
nq – IntegerInput
the number of quantiles requested.
q[nq] – const doubleInput
On entry: the quantiles to be calculated, in ascending order. Note that these must be between and , with returning the smallest element and the largest.
- , for ;
- , for .
qv[nq] – doubleOutput
On exit: contains the quantile specified by the value provided in , or an interpolated value if the quantile falls between two data values.
fail – NagError *Input/Output
The NAG error argument (see Section 3.6
in the Essential Introduction).
6 Error Indicators and Warnings
On entry, argument had an illegal value.
On entry, .
On entry, .
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG
On entry, q
was not in ascending order.
On entry, an element of q
was less than
or greater than
Internal error. Please contact NAG
The average time taken by nag_double_quantiles (g01amc) is approximately proportional to . The worst case time is proportional to but this is extremely unlikely to occur.
This example computes a list of quantiles from an array of doubles and an array of point values.
9.1 Program Text
Program Text (g01amce.c)
9.2 Program Data
Program Data (g01amce.d)
9.3 Program Results
Program Results (g01amce.r)