Quantiles and Order Statistics |
Hereinafter the following convention is used:
denotes data container element, i = 0..n-1. For vector, array of doubles and array of nullable doubles 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.
where X is a vector or an array.
For an n-element vector X, quantile is computed as follows:
The sorted values in X are taken as the (0.5/n), (1.5/n), ..., ([n–0.5]/n) quantiles.
Linear interpolation is used to compute quantiles for probabilities between (0.5/n) and ([n–0.5]/n).
The minimum or maximum values in X are assigned to quantiles for probabilities outside that range.
Cumulative distribution function is defined as follows:
For an n-element vector X, cumulative distribution function calculation is the reversed process of quantile calculation:
For all elements except the greatest and the smallest one the corresponding p-value is calculated.
For the given x the corresponding p-value is picked. Generally it is found between two consecutive values.
Linear interpolation is used to compute the CDF value.
For all values except the boundary values the following formula is valid:
Operation | Description | Performance |
---|---|---|
minimum | Minimal value. | |
maximum | Maximal value. | |
minimum index | Returns index of minimal value in container. | |
maximum index | Returns index of maximal value in container. | |
absolute minimum | Returns minimal absolute value in container. AbsoluteMinimum(Vector, Boolean) | |
absolute maximum | Returns maximal absolute value in container. AbsoluteMaximum(Vector, Boolean) | |
absolute minimum index | Returns index of minimal absolute value in container. AbsoluteMinimumIndex(Vector, Boolean) | |
absolute maximum index | Returns index of maximal absolute value in container. AbsoluteMaximumIndex(Vector, Boolean) | |
minimum, maximum statistics | Returns minimal, maximal vales in container and its indexes. MinimumMaximum(Vector, Boolean) | |
order statistic | Returns order statistic of specified rank from container's value. I.e. rank-th minimal value. OrderStatistic(Vector, Int32, Boolean) | |
quantile | Returns quantile of specified level from container's value. Quantile(Vector, Double, Boolean) | |
cumulative distribution | Get estimation of Distribution Function. Returns probability that random value less or equal to x. CumulativeDistribution(Vector, Double, Boolean) CumulativeDistribution(IEnumerableDouble, Double, Boolean) CumulativeDistribution(IEnumerableNullableDouble, Double, Boolean) |
The example of quantiles and order statistics usage:
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}