weightedQuantile
weightedQuantile(
x,weights,p):number
Defined in: src/weighted_quantile.js:20
The weighted quantile is the value whose cumulative weight reaches the requested probability.
This implementation sorts value/weight pairs by value, then returns the
first value where cumulative weight is greater than or equal to p times the
total weight. When p is an array, the result is also an array containing the
appropriate weighted quantiles in input order.
Parameters
Section titled “Parameters”number[]
sample of one or more data points
weights
Section titled “weights”number[]
non-negative weights for each data point
number | number[]
the desired quantile, as a number between 0 and 1
Returns
Section titled “Returns”number
weighted quantile
Throws
Section titled “Throws”if x is empty, weights is a different length than x, all weights are zero, a weight is negative, or p is outside of the range from 0 to 1
Example
Section titled “Example”weightedQuantile([1, 2, 3], [1, 1, 2], 0.5); // => 2