quantile

Returns the quantile in a data vector for a cumulative probability.

Takes a data vector and a probability and returns the quantile cut point for the probability. The vector must be sorted and the probability in the range [0.0, 1.0]. The interpolation methods available are the same as in R and available in a number of statistical packages. See the R documentation or wikipedia for details (https://en.wikipedia.org/wiki/Quantile).

double
quantile
(
ProbType
Range
)
if (
isRandomAccessRange!Range &&
hasLength!Range
&&
isNumeric!(ElementType!Range)
&&
isFloatingPoint!ProbType
)
in { import std.algorithm : isSorted; assert (0.0 <= prob && prob <= 1.0); assert (method >= QuantileInterpolation.min && method <= QuantileInterpolation.max); assert (data.isSorted); }

Examples

double data = [22, 57, 73, 97, 113];
double median = quantile(0.5, data);   // 73
auto q1 = [0.25, 0.5, 0.75].map!(p => p.quantile(data));  // 57, 73, 97
auto q2 = [0.25, 0.5, 0.75].map!(p => p.quantile(data), QuantileInterpolation.R8);  //45.3333, 73, 102.333

Meta