示例#1
0
def demand_curves(ranking_provider,
                  vax_policy,
                  phis=[25, 50, 100, 200],
                  phi_benchmark=25,
                  N_state=N_TN):
    wtp_rankings = {phi: ranking_provider(phi, vax_policy) for phi in phis}

    figure = plt.figure()
    lines = []

    # benchmark
    benchmark = wtp_rankings[phi_benchmark]
    x_pop = list(
        chain(*zip(benchmark.loc[0]["num_vax"].shift(1).fillna(0),
                   benchmark.loc[0]["num_vax"])))
    y_wtp = list(
        chain(*zip(benchmark.loc[0]["wtp_pc_usd"], benchmark.loc[0]
                   ["wtp_pc_usd"])))
    lines.append(
        plt.plot(x_pop, y_wtp, figure=figure, color="black", linewidth=2)[0])
    lines.append(plt.plot(0, 0, color="white")[0])

    # plot dynamic curve
    for (phi, all_wtp) in wtp_rankings.items():
        daily_doses = phi * percent * annually * N_state
        distributed_doses = 0
        x_pop = []
        y_wtp = []
        t_vax = []
        ranking = 0
        for t in range(simulation_range):
            wtp = all_wtp.loc[t].reset_index()
            ranking = wtp[(wtp.index >= ranking)
                          & (wtp.num_vax > distributed_doses)].index.min()
            if np.isnan(ranking):
                break
            x_pop += [distributed_doses, distributed_doses + daily_doses]
            t_vax += [t, t + 1]
            y_wtp += [wtp.iloc[ranking].wtp_pc_usd] * 2
            distributed_doses += daily_doses
        lines.append(
            plt.plot(x_pop,
                     y_wtp,
                     label=f"dynamic, {vax_policy}, $\phi = ${phi}%",
                     figure=figure)[0])
    plt.legend(lines, [f"static, t = 0, $\phi = ${phi_benchmark}%", ""] +
               [f"dynamic, {vax_policy}, $\phi = ${phi}%" for phi in phis],
               title="allocation",
               title_fontsize="24",
               fontsize="20")
    plt.xticks(fontsize="20")
    plt.yticks(fontsize="20")
    plt.PlotDevice().ylabel("WTP (USD)\n").xlabel("\nnumber vaccinated")
    plt.ylim(0, 350)
    plt.xlim(left=0, right=N_TN)
    plt.show()
示例#2
0
    summed_wtp_soc = np.median(evaluated_WTP_pc[50, "random"] -
                               evaluated_WTP_p[50, "random"],
                               axis=0)
    # plot_component_breakdowns(summed_wtp_soc, summed_wtp_priv, "social", "private", semilogy = False)
    # plt.show()

    # # dist x age
    per_district_WTP_percentiles = {
        (district, *parse_tag(tag)): np.percentile(wtp[0, :, :], [50, 5, 95],
                                                   axis=0)
        for ((district, tag), wtp) in district_WTP.items()
    }
    per_district_YLL_percentiles = {
        (district, *parse_tag(tag)): np.percentile(yll, [50, 5, 95], axis=0)
        for ((district, tag), yll) in district_YLL.items()
    }

    # plot_district_age_distribution(per_district_WTP_percentiles, "per capita WTP (USD)", "D", N_jk = N_jk_dicts)
    # plt.show()
    # plot_district_age_distribution(per_district_YLL_percentiles, "YLL"                 , "o")
    # plt.show()

    # demand curves
    ranking_provider = get_wtp_ranking(district_WTP)
    demand_curves(ranking_provider, "mortality")
    plt.show()
    demand_curves(ranking_provider, "random")
    plt.show()
    demand_curves(ranking_provider, "contact")
    plt.show()