Click or drag to resize

Quantiles and Order Statistics

Hereinafter the following convention is used:

DSxi denotes data container element, i = 0..n-1. For vector, array of doubles and array of nullable doubles DSxi denotes an array element or vector element.

Order statistic allows to get element by its order in the series when values are ordered from the smallest one to the greatest one. This section also includes methods that allow calculating quantile and cumulative distribution function.

The p-th quantile, where p is between 0 and 1, is the value that has a proportion p of the data below the value.

DSQuantile

where X is a vector or an array.

For an n-element vector X, quantile is computed as follows:

  1. The sorted values in X are taken as the (0.5/n), (1.5/n), ..., ([n–0.5]/n) quantiles.

  2. Linear interpolation is used to compute quantiles for probabilities between (0.5/n) and ([n–0.5]/n).

  3. The minimum or maximum values in X are assigned to quantiles for probabilities outside that range.

Cumulative distribution function is defined as follows:

DSCD

For an n-element vector X, cumulative distribution function calculation is the reversed process of quantile calculation:

  1. For all elements except the greatest and the smallest one the corresponding p-value is calculated.

  2. For the given x the corresponding p-value is picked. Generally it is found between two consecutive values.

  3. Linear interpolation is used to compute the CDF value.

For all values except the boundary values the following formula is valid:

DSCdfP

Methods

Operation

Description

Performance

minimum

Minimal value.

DSMin

StaticMinimum(Vector, Boolean)

StaticMinimum(IEnumerableDouble, Boolean)

StaticMinimum(IEnumerableNullableDouble, Boolean)

maximum

Maximal value.

DSMax

StaticMaximum(Vector, Boolean)

StaticMaximum(IEnumerableDouble, Boolean)

StaticMaximum(IEnumerableNullableDouble, Boolean)

minimum index

Returns index of minimal value in container.

DSMinI

StaticMinimumIndex(Vector, Boolean)

StaticMinimumIndex(IEnumerableDouble, Boolean)

StaticMinimumIndex(IEnumerableNullableDouble, Boolean)

maximum index

Returns index of maximal value in container.

DSMaxI

StaticMaximumIndex(Vector, Boolean)

StaticMaximumIndex(IEnumerableDouble, Boolean)

StaticMaximumIndex(IEnumerableNullableDouble, Boolean)

absolute minimum

Returns minimal absolute value in container.

DSAbs Min

StaticAbsoluteMinimum(Vector, Boolean)

StaticAbsoluteMinimum(IEnumerableDouble, Boolean)

StaticAbsoluteMinimum(IEnumerableNullableDouble, Boolean)

absolute maximum

Returns maximal absolute value in container.

DSAbs Max

StaticAbsoluteMaximum(Vector, Boolean)

StaticAbsoluteMaximum(IEnumerableDouble, Boolean)

StaticAbsoluteMaximum(IEnumerableNullableDouble, Boolean)

absolute minimum index

Returns index of minimal absolute value in container.

DSAbs MinI

StaticAbsoluteMinimumIndex(Vector, Boolean)

StaticAbsoluteMinimumIndex(IEnumerableDouble, Boolean)

StaticAbsoluteMinimumIndex(IEnumerableNullableDouble, Boolean)

absolute maximum index

Returns index of maximal absolute value in container.

DSAbs MaxI

StaticAbsoluteMaximumIndex(Vector, Boolean)

StaticAbsoluteMaximumIndex(IEnumerableDouble, Boolean)

StaticAbsoluteMaximumIndex(IEnumerableNullableDouble, Boolean)

minimum, maximum statistics

Returns minimal, maximal vales in container and its indexes.

StaticMinimumMaximum(Vector, Boolean)

StaticMinimumMaximum(IEnumerableDouble, Boolean)

StaticMinimumMaximum(IEnumerableNullableDouble, Boolean)

order statistic

Returns order statistic of specified rank from container's value. I.e. rank-th minimal value.

DSOrder Stat

StaticOrderStatistic(Vector, Int32, Boolean)

StaticOrderStatistic(IEnumerableDouble, Int32, Boolean)

StaticOrderStatistic(IEnumerableNullableDouble, Int32, Boolean)

quantile

Returns quantile of specified level from container's value.

StaticQuantile(Vector, Double, Boolean)

StaticQuantile(IEnumerableDouble, Double, Boolean)

StaticQuantile(IEnumerableNullableDouble, Double, Boolean)

cumulative distribution

Get estimation of Distribution Function. Returns probability that random value less or equal to x.

StaticCumulativeDistribution(Vector, Double, Boolean)

StaticCumulativeDistribution(IEnumerableDouble, Double, Boolean)

StaticCumulativeDistribution(IEnumerableNullableDouble, Double, Boolean)

Code Sample

The example of quantiles and order statistics usage:

C#
 1using System;
 2using FinMath.LinearAlgebra;
 3using FinMath.Statistics;
 4
 5namespace FinMath.Samples
 6{
 7    class VectorQuantilesSample
 8    {
 9        static void Main()
10        {
11            // Input parameters.
12            const Int32 observationsCount = 10;
13            const Int32 statisticRank = 4;
14            const Double quantilePValue = 0.75;
15
16            // Generate input vector.
17            Vector vector = Vector.Random(observationsCount);
18            Console.WriteLine("Inpute vector:");
19            Console.WriteLine("  " + vector.ToString("0.000"));
20
21            Console.WriteLine("Results:");
22            Console.WriteLine("  Absolute maximum index: " + vector.AbsoluteMaximumIndex());
23            Console.WriteLine($"  {statisticRank}-th order statistic: {vector.OrderStatistic(statisticRank):0.000}");
24            Double quantile = vector.Quantile(quantilePValue);
25            Console.WriteLine($"  Quantile of the level {quantilePValue}: {quantile:0.000}");
26            Console.WriteLine($"  Сumulative distribution function of argument {quantile:0.000}:  {vector.CumulativeDistribution(quantile):0.000}");
27        }
28    }
29}

See Also