g01am finds specified quantiles from a vector of unsorted data.

# Syntax

C# |
---|

public static void g01am( int n, double[] rv, int nq, double[] q, double[] qv, out int ifail ) |

Visual Basic |
---|

Public Shared Sub g01am ( _ n As Integer, _ rv As Double(), _ nq As Integer, _ q As Double(), _ qv As Double(), _ <OutAttribute> ByRef ifail As Integer _ ) |

Visual C++ |
---|

public: static void g01am( int n, array<double>^ rv, int nq, array<double>^ q, array<double>^ qv, [OutAttribute] int% ifail ) |

F# |
---|

static member g01am : n : int * rv : float[] * nq : int * q : float[] * qv : float[] * ifail : int byref -> unit |

#### Parameters

- n
- Type: System..::..Int32
*On entry*: the number of elements in the input vector rv.*Constraint*: ${\mathbf{n}}>0$.

- rv
- Type: array<System..::..Double>[]()[][]An array of size [n]
*On entry*: the vector whose quantiles are to be determined.*On exit*: the order of the elements in rv is not, in general, preserved.

- nq
- Type: System..::..Int32
*On entry*: the number of quantiles requested.*Constraint*: ${\mathbf{nq}}>0$.

- q
- Type: array<System..::..Double>[]()[][]An array of size [nq]
*On entry*: the quantiles to be calculated, in ascending order. Note that these must be between $0.0$ and $1.0$, with $0.0$ returning the smallest element and $1.0$ the largest.*Constraints*:- $0.0\le {\mathbf{q}}\left[\mathit{i}-1\right]\le 1.0$, for $\mathit{i}=1,2,\dots ,{\mathbf{nq}}$;
- ${\mathbf{q}}\left[\mathit{i}-1\right]\le {\mathbf{q}}\left[\mathit{i}+1-1\right]$, for $\mathit{i}=1,2,\dots ,{\mathbf{nq}}-1$.

- qv
- Type: array<System..::..Double>[]()[][]An array of size [nq]
*On exit*: ${\mathbf{qv}}\left[i-1\right]$ contains the quantile specified by the value provided in ${\mathbf{q}}\left[i-1\right]$, or an interpolated value if the quantile falls between two data values.

- ifail
- Type: System..::..Int32%
*On exit*: ${\mathbf{ifail}}={0}$ unless the method detects an error or a warning has been flagged (see [Error Indicators and Warnings]).

# 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 $0.5$ quantile because half the values are less than or equal to it; and the $0.25$ quantile is the $25$th percentile.

g01am 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.

# References

Singleton R C (1969) An efficient algorithm for sorting with minimal storage: Algorithm 347

*Comm. ACM***12**185–187# Error Indicators and Warnings

Errors or warnings detected by the method:

- ${\mathbf{ifail}}=1$
On entry, ${\mathbf{n}}<1$.

- ${\mathbf{ifail}}=2$
On entry, ${\mathbf{nq}}<1$.

- ${\mathbf{ifail}}=3$
- On entry, some ${\mathbf{q}}<0.0$ or ${\mathbf{q}}>1.0$.

- ${\mathbf{ifail}}=4$
- On entry, q is not in ascending order.

- ${\mathbf{ifail}}=5$

# Accuracy

Not applicable.

# Parallelism and Performance

None.

# Further Comments

The average time taken by g01am is approximately proportional to ${\mathbf{n}}\times \left(1+\mathrm{log}\left({\mathbf{nq}}\right)\right)$. The worst case time is proportional to ${{\mathbf{n}}}^{2}$ but this is extremely unlikely to occur.

# Example

This example computes a list of quantiles from an array of reals and an array of point values.

Example program (C#): g01ame.cs