quantile function
Returns the p-quantile of the given iterable, where p is in 0, 1.
Uses the R-7 method (linear interpolation of modes).
Implementation
double? quantile(Iterable<num> iterable, double p) {
final values = iterable.toList()..sort();
if (values.isEmpty) return null;
if (p <= 0) return values.first.toDouble();
if (p >= 1) return values.last.toDouble();
final n = values.length;
final index = (n - 1) * p;
final lo = index.floor();
final hi = index.ceil();
final loValue = values[lo];
if (lo == hi) return loValue.toDouble();
return loValue + (values[hi] - loValue) * (index - lo);
}