NAG Library Routine Document
G01AMF finds specified quantiles from a vector of unsorted data.
||N, NQ, IFAIL
||RV(N), Q(NQ), QV(NQ)
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.
G01AMF 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
- 1: N – INTEGERInput
: the number of elements in the input vector RV
- 2: RV(N) – REAL (KIND=nag_wp) arrayInput/Output
On entry: the vector whose quantiles are to be determined.
: the order of the elements in RV
is not, in general, preserved.
- 3: NQ – INTEGERInput
On entry: the number of quantiles requested.
- 4: Q(NQ) – REAL (KIND=nag_wp) arrayInput
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 .
- 5: QV(NQ) – REAL (KIND=nag_wp) arrayOutput
On exit: contains the quantile specified by the value provided in , or an interpolated value if the quantile falls between two data values.
- 6: IFAIL – INTEGERInput/Output
must be set to
. If you are unfamiliar with this parameter you should refer to Section 3.3
in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value
is recommended. If the output of error messages is undesirable, then the value
is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is
. When the value is used it is essential to test the value of IFAIL on exit.
unless the routine detects an error or a warning has been flagged (see Section 6
6 Error Indicators and Warnings
If on entry
, explanatory error messages are output on the current error message unit (as defined by X04AAF
Errors or warnings detected by the routine:
On entry, some or .
On entry, Q
is not in ascending order.
Internal error. Check all array sizes and calls to G01AMF. Please contact NAG
The average time taken by G01AMF 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 reals and an array of point values.
9.1 Program Text
Program Text (g01amfe.f90)
9.2 Program Data
Program Data (g01amfe.d)
9.3 Program Results
Program Results (g01amfe.r)