Skip to content

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.

number[]

sample of one or more data points

number[]

non-negative weights for each data point

number | number[]

the desired quantile, as a number between 0 and 1

number

weighted quantile

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

weightedQuantile([1, 2, 3], [1, 1, 2], 0.5); // => 2