I'm trying to calculate P50 and P95 for streaming list of integers. Here's an example code: Live On Compiler Explorer
#include <boost/accumulators/accumulators.hpp>
#include <boost/accumulators/statistics.hpp>
#include <boost/accumulators/statistics/extended_p_square_quantile.hpp>
namespace ba = boost::accumulators;
int main() {
std::vector<int> values = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
std::vector<double> probs = {0.5, 0.95};
ba::accumulator_set<int, ba::stats<ba::tag::extended_p_square_quantile>> //
acc(ba::extended_p_square_probabilities = probs);
for (auto val : values) {
acc(val);
}
std::cout << "P: " << ba::quantile(acc, ba::quantile_probability = 0.5) << " "
<< ba::quantile(acc, ba::quantile_probability = 0.95) << std::endl;
}
But this is returning unexpected values:
P: 3 7
I expected the answer to be 5 9. How do I get what I want?
The statistic is an estimation. Not only should you feed it more data, you may also expect different values. Perhaps the 95% percentile estimate should be closer to 10.
You can see it at work with this expansion of the test program:
Live On Coliru
Printing: