NAG CPP Interface
nagcpp::stat::quantiles (g01am)
1
Purpose
quantiles finds specified quantiles from a vector of unsorted data.
2
Specification
#include "g01/nagcpp_g01am.hpp"
template <typename RV, typename Q, typename QV>
void function quantiles(RV &&rv, const Q &q, QV &&qv, OptionalG01AM opt)
template <typename RV, typename Q, typename QV>
void function quantiles(RV &&rv, const Q &q, QV &&qv)
3
Description
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.
quantiles 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.
4
References
Singleton R C (1969) An efficient algorithm for sorting with minimal storage: Algorithm 347 Comm. ACM 12 185–187
5
Arguments
-
1:
– double array
Input/Output
-
On entry: the vector whose quantiles are to be determined.
On exit: the order of the elements in
rv is not, in general, preserved.
-
2:
– double array
Input
-
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.
Constraints:
- , for ;
- , for .
-
3:
– double array
Output
-
On exit: contains the quantile specified by the value provided in , or an interpolated value if the quantile falls between two data values.
-
4:
– OptionalG01AM
Input/Output
-
Optional parameter container, derived from
Optional.
5.1Additional Quantities
- 1:
- The number of elements in the input vector rv
- 2:
- The number of quantiles requested.
6
Exceptions and Warnings
Errors or warnings detected by the function:
All errors and warnings have an associated numeric error code field,
errorid, stored either as a member of the thrown exception object (see
errorid), or as a member of
opt.
ifail, depending on how errors
and warnings are being handled (see
Error Handling for more details).
- Raises: ErrorException
-
- On entry, .
Constraint: .
- On entry, .
Constraint: .
- On entry, an element of q was less than or greater than .
- On entry, q was not in ascending order.
- On entry, argument must be a vector of size array.
Supplied argument has dimensions.
- On entry, argument must be a vector of size array.
Supplied argument was a vector of size .
- On entry, argument must be a vector of size array.
The size for the supplied array could not be ascertained.
- On entry, the raw data component of is null.
- On entry, unable to ascertain a value for .
- An unexpected error has been triggered by this routine.
- Your licence key may have expired or may not have been installed correctly.
- Dynamic memory allocation failed.
7
Accuracy
Not applicable.
8
Parallelism and Performance
Please see the description for the underlying computational routine in this section of the
FL Interface documentation.
The average time taken by quantiles is approximately proportional to . The worst case time is proportional to but this is extremely unlikely to occur.
10
Example
This example computes a list of quantiles from an array of reals and an array of point values.