Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""
Interpolates a percentile value assuming that the data is drawn
from a Pareto distribution. Good for income and other highly
skewed distributions.
"""
i, bin, counts = _bin_select(data_list, percentile)
lower_bound, upper_bound = bin
ratio_proportion = (percentile * sum(counts))/sum(counts[i:])
ratio_overall = sum(counts[(i + 1):])/sum(counts[i:])
ratio_bounds = upper_bound/lower_bound
return lower_bound * math.exp((math.log(ratio_proportion) /
math.log(ratio_overall)) *
math.log(ratio_bounds))
def pareto_percentile(data_list, percentile=0.5):
"""
Interpolates a percentile value assuming that the data is drawn
from a Pareto distribution. Good for income and other highly
skewed distributions.
"""
i, bin, counts = _bin_select(data_list, percentile)
lower_bound, upper_bound = bin
ratio_proportion = (percentile * sum(counts))/sum(counts[i:])
ratio_overall = sum(counts[(i + 1):])/sum(counts[i:])
ratio_bounds = upper_bound/lower_bound
return lower_bound * math.exp((math.log(ratio_proportion) /
math.log(ratio_overall)) *
math.log(ratio_bounds))