hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_stat_quantiles (g01am)

Purpose

nag_stat_quantiles (g01am) finds specified quantiles from a vector of unsorted data.

Syntax

[qv, ifail] = g01am(rv, q, 'n', n, 'nq', nq)
[qv, ifail] = nag_stat_quantiles(rv, q, 'n', n, 'nq', nq)
Note: the interface to this routine has changed since earlier releases of the toolbox:
Mark 23: rv no longer an output parameter
.

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.50.5 quantile because half the values are less than or equal to it; and the 0.250.25 quantile is the 2525th percentile.
nag_stat_quantiles (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

Parameters

Compulsory Input Parameters

1:     rv(n) – double array
n, the dimension of the array, must satisfy the constraint n > 0n>0.
The vector whose quantiles are to be determined.
2:     q(nq) – double array
nq, the dimension of the array, must satisfy the constraint nq > 0nq>0.
The quantiles to be calculated, in ascending order. Note that these must be between 0.00.0 and 1.01.0, with 0.00.0 returning the smallest element and 1.01.0 the largest.
Constraints:
  • 0.0q(i)1.00.0qi1.0, for i = 1,2,,nqi=1,2,,nq;
  • q(i)q(i + 1)qiqi+1, for i = 1,2,,nq1i=1,2,,nq-1.

Optional Input Parameters

1:     n – int64int32nag_int scalar
Default: The dimension of the array rv.
The number of elements in the input vector rv.
Constraint: n > 0n>0.
2:     nq – int64int32nag_int scalar
Default: The dimension of the array q.
The number of quantiles requested.
Constraint: nq > 0nq>0.

Input Parameters Omitted from the MATLAB Interface

None.

Output Parameters

1:     qv(nq) – double array
qv(i)qvi contains the quantile specified by the value provided in q(i)qi, or an interpolated value if the quantile falls between two data values.
2:     ifail – int64int32nag_int scalar
ifail = 0ifail=0 unless the function detects an error (see [Error Indicators and Warnings]).

Error Indicators and Warnings

Errors or warnings detected by the function:
  ifail = 1ifail=1
On entry,n < 1n<1.
  ifail = 2ifail=2
On entry,nq < 1nq<1.
  ifail = 3ifail=3
On entry, some q < 0.0q<0.0 or q > 1.0q>1.0.
  ifail = 4ifail=4
On entry, q is not in ascending order.
  ifail = 5ifail=5
Internal error. Check all array sizes and calls to nag_stat_quantiles (g01am). Please contact NAG.

Accuracy

Not applicable.

Further Comments

The average time taken by nag_stat_quantiles (g01am) is approximately proportional to n × (1 + log(nq))n×(1+log(nq)). The worst case time is proportional to n2n2 but this is extremely unlikely to occur.

Example

function nag_stat_quantiles_example
rv = [4.9;
     7;
     3.9;
     9.5;
     1.3;
     3.1;
     9.7;
     0.3;
     8.5;
     0.6;
     6.2];
q = [0.25;
     0.5;
     1];
[qv, ifail] = nag_stat_quantiles(rv, q)
 

qv =

    2.2000
    4.9000
    9.7000


ifail =

                    0


function g01am_example
rv = [4.9;
     7;
     3.9;
     9.5;
     1.3;
     3.1;
     9.7;
     0.3;
     8.5;
     0.6;
     6.2];
q = [0.25;
     0.5;
     1];
[qv, ifail] = g01am(rv, q)
 

qv =

    2.2000
    4.9000
    9.7000


ifail =

                    0



PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2013