How to use the census.math 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
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))
github datamade / census / census / math.py View on Github external
between variables
    """
    
    warnings.warn('The calculation of the margin of error of a sum of variables assumes no covariance between variables. The Census does not provide data on covariance and suggests this method as an approximation. https://www.census.gov/content/d`am/Census/programs-surveys/acs/guidance/training-presentations/20170419_MOE.pdf')
    
    moe_sq = sum(moe**2 for value, moe in zip(values, moes) if value != 0)

    try:
        # If there are multiple zero values, Census advises to use
        # only the largest associated MOE,
        # https://www.census.gov/content/dam/Census/programs-surveys/acs/guidance/training-presentations/20170419_MOE.pdf, page 51
        moe_sq += max(moe for value, moe in zip(values, moes) if value == 0)**2
    except ValueError:
        pass

    return math.sqrt(moe_sq)