Exemplo n.º 1
0
def _get_stats_for_state(deaths, pop):
    current_week = deaths[-7:]
    last_week = deaths[-14:-7]
    last_week_2 = deaths[-21:-14]
    the_dict = {}
    resample1, resample2 = bootstrap.resample_two_samples(last_week, current_week, num_iterations = 1000)
    both = bootstrap.combine_resamples(last_week, current_week, resample1, resample2)
    p_value = bootstrap.get_p_value(both)

    resample3, resample4 = bootstrap.resample_two_samples(last_week_2, last_week, num_iterations = 1000)
    both2 = bootstrap.combine_resamples(last_week_2, current_week, resample3, resample4)
    p_value2 = bootstrap.get_p_value(both2)

    the_dict['p_value_last_week'] =  p_value
    the_dict['p_value_last_week2'] =  p_value2
    the_dict['current_week_mean'] = np.mean(current_week)
    the_dict['last_week_mean'] = np.mean(last_week)
    the_dict['last_week_mean_2'] = np.mean(last_week_2)
    if pop == None:
        the_dict['current_week_per_million'] = None
        the_dict['last_week_per_million'] = None
    else:
        the_dict['current_week_per_million'] = round(float(np.mean(current_week))/pop * 1000000, 1)
        the_dict['last_week_per_million'] = round(float(np.mean(last_week))/pop * 1000000, 1)
    return the_dict
Exemplo n.º 2
0
def _get_stats_for_state(deaths, cases, pop):
    current_week = deaths[-7:]
    last_week = deaths[-14:-7]
    last_week_2 = deaths[-21:-14]
    current_week_cases = cases[-7:]
    last_week_cases = cases[-14:-7]
    last_week_2_cases = cases[-21:-14]
    the_dict = {}
    for i in [
        (last_week, current_week, 'p_value_death_current_last'),
        (last_week_2, current_week, 'p_value_death_last_last2'),
        (last_week_cases, current_week_cases, 'p_value_cases_current_last'),
        (last_week_2_cases, current_week_cases, 'p_value_cases_last_last2'),
    ]:
        resample1, resample2 = bootstrap.resample_two_samples(
            i[0], i[1], num_iterations=1000)
        both = bootstrap.combine_resamples(last_week, current_week, resample1,
                                           resample2)
        p_value = bootstrap.get_p_value(both)
        the_dict[i[2]] = p_value
    the_dict['current_week_mean'] = np.mean(current_week)
    the_dict['last_week_mean'] = np.mean(last_week)
    the_dict['last_week_mean_2'] = np.mean(last_week_2)
    the_dict['current_week_cases_mean'] = np.mean(current_week_cases)
    the_dict['last_week_cases_mean'] = np.mean(last_week_cases)
    the_dict['last_week_cases_mean_2'] = np.mean(last_week_2_cases)
    if pop == None:
        the_dict['current_week_per_million'] = None
        the_dict['last_week_per_million'] = None
        the_dict['current_week_cases_per_million'] = None
        the_dict['last_week_cases_per_million'] = None
    else:
        the_dict['current_week_per_million'] = round(
            float(np.mean(current_week)) / pop * 1000000, 1)
        the_dict['last_week_per_million'] = round(
            float(np.mean(last_week)) / pop * 1000000, 1)
        the_dict['current_week_cases_per_million'] = round(
            float(np.mean(current_week_cases)) / pop * 1000000, 1)
        the_dict['last_week_cases_per_million'] = round(
            float(np.mean(last_week_cases)) / pop * 1000000, 1)
    return the_dict
Exemplo n.º 3
0
 def test_pvalue(self):
     sample1 = [1, 2, 3, 5]
     sample2 = [1, 2, 3, 5]
     r1, r2 = bootstrap.resample_two_samples(sample1, sample2)
     b = bootstrap.combine_resamples(sample1, sample2, r1, r2)
     bootstrap.get_p_value(b)