I've been struggling to find a way of calculating percentiles of a vector X given weights W that is continuous in W at zero. That is, as an element of W tends to zero, I would want the result of the percentile calculation to be the same as if the respective value of X had not been included in the initial vector. Can anyone suggest a weighted percentile algorithm that respects this property? Thanks.
Asked
Active
Viewed 3,490 times
2
-
Though this topic was abandoned, stackoverflow has not only the answer, but also the python code for such function http://stackoverflow.com/a/29677616/498892, http://stackoverflow.com/a/28720410/498892 – Alleo Apr 16 '15 at 18:58
1 Answers
0
You can solve this problem with simulation to get an answer that is correct in expectation.
Renormalize the weights to sum to 1, then draw n samples with replacement from X with probability W. Calculate the percentiles of the n samples, and you're finished. You'll need more n as max(W)/min(W) increases, but even drawing a ten million samples is fast on a modern machine.

Max Shron
- 946
- 7
- 6