How to use the census.math.log function in census

To help you get started, we’ve selected a few census examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github datamade / census / census / math.py View on Github external
"""
    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))
github datamade / census / census / math.py View on Github external
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))