def __init__(self, csv_file_name, wtps, poly_degree=2):

        scenario_df = Cls.ScenarioDataFrame(csv_file_name=csv_file_name)

        self.wtps = wtps
        self.selectWTPs = []
        self.costs = []
        self.effects = []
        self.utilization = []
        self.nSwitches = []

        for scenario_name in scenario_df.scenarios:

            if scenario_name[0:3] == 'D:2':
                # store wtp value
                i = scenario_name.find('WTP')
                self.selectWTPs.append(float(scenario_name[i + 5:]))

                # total cost
                cost_mean, cost_CI = scenario_df.get_mean_interval(
                    scenario_name=scenario_name, outcome_name='Total Cost')
                self.costs.append(cost_mean)

                # QALY
                effect_mean, effect_CI = scenario_df.get_mean_interval(
                    scenario_name=scenario_name, outcome_name='DALY')
                self.effects.append(effect_mean)

                # utilization of social distancing
                utilization_mean, utilization_CI = scenario_df.get_mean_interval(
                    scenario_name=scenario_name,
                    outcome_name='Utilization (unit of time): Social Distancing'
                )
                self.utilization.append(utilization_mean)

                # Number of Switches
                n_switches_mean, n_switches_CI = scenario_df.get_mean_interval(
                    scenario_name=scenario_name,
                    outcome_name='Number of Switches')
                self.nSwitches.append(n_switches_mean)

        self.costRegression = Reg.PolyRegression(
            self.selectWTPs, [c * 1e-6 for c in self.costs],
            degree=poly_degree)

        self.dalyRegression = Reg.PolyRegression(
            self.selectWTPs, [e * 1e-3 for e in self.effects],
            degree=poly_degree)

        self.utilRegression = Reg.PolyRegression(self.selectWTPs,
                                                 self.utilization,
                                                 degree=poly_degree)

        self.nSwitchesRegression = Reg.PolyRegression(self.selectWTPs,
                                                      self.nSwitches,
                                                      degree=1)
    def __init__(self, csv_file_name, poly_degree=2):

        scenario_df = Cls.ScenarioDataFrame(csv_file_name=csv_file_name)

        self.wtps = []
        self.costs = []
        self.effects = []
        self.nSwitches = []

        for scenario_name in scenario_df.scenarios:

            if scenario_name[0:3] == 'D:3':
                # store wtp value
                i = scenario_name.find('WTP')
                self.wtps.append(float(scenario_name[i + 5:]))

                # total cost
                cost_mean, cost_CI = scenario_df.get_mean_interval(
                    scenario_name=scenario_name, outcome_name='Total Cost')
                self.costs.append(cost_mean)

                # effect
                effect_mean, effect_CI = scenario_df.get_mean_interval(
                    scenario_name=scenario_name, outcome_name='DALY')
                self.effects.append(effect_mean / 10)

                # Number of Switches
                n_switches_mean, n_switches_CI = scenario_df.get_mean_interval(
                    scenario_name=scenario_name,
                    outcome_name='Number of Switches')
                self.nSwitches.append(n_switches_mean)

        self.costRegression = Reg.PolyRegression(self.wtps,
                                                 self.costs,
                                                 degree=poly_degree)
        self.costRegression = Reg.ExpRegression(self.wtps, self.costs)

        self.effectRegression = Reg.PolyRegression(self.wtps,
                                                   self.effects,
                                                   degree=poly_degree)
        self.effectRegression = Reg.ExpRegression(
            self.wtps, self.effects, if_c0_zero=True)  # p0=[0, 1, -1])

        self.nSwitchesRegression = Reg.PolyRegression(self.wtps,
                                                      self.nSwitches,
                                                      degree=poly_degree)
import apace.ScenariosClasses as Cls
import apace.VisualizeScenarios as Vis
import covid19.Support as Sup
import SimPy.FormatFunctions as F

SUFX = ''
# SUFX = '4WeekMin'

Cls.POLY_DEGREES = 2
scenarioDfFixedPeriodic = Cls.ScenarioDataFrame(
    csv_file_name='csv_files/PolicyEvals/PolicyEvalsFixedPeriodic{}.csv'.
    format(SUFX))
scenarioDfAdaptiveI = Cls.ScenarioDataFrame(
    csv_file_name='csv_files/PolicyEvals/PolicyEvalAdaptiveFt{}.csv'.format(
        SUFX))

policy_definitions = Sup.PolicyDefinitions()

# series to display on the cost-effectiveness plane
fixed_interval = Cls.SetOfScenarios(
    name='Predetermined Duration',
    scenario_df=scenarioDfFixedPeriodic,
    color='blue',
    marker='o',
    conditions_on_variables=policy_definitions.FixedIntervalVarConditions,
    if_find_frontier=False,
    if_show_fitted_curve=True,
    labels_shift_x=-0.025,
    labels_shift_y=0.02)

periodic = Cls.SetOfScenarios(
Beispiel #4
0
import apace.ScenariosClasses as Cls
import apace.VisualizeScenarios as Vis
import covid19.Support as Sup
import SimPy.FormatFunctions as F

SUFX = ''
# SUFX = '4WeekMin'


Cls.POLY_DEGREES = 2
scenarioDfFixedPeriodic = Cls.ScenarioDataFrame(
    csv_file_name='csv_files/PolicyEvals/PolicyEvalsFixedPeriodic{}.csv'.format(SUFX))
scenarioDfAdaptiveIt = Cls.ScenarioDataFrame(
    csv_file_name='csv_files/PolicyEvals/PolicyEvalAdaptiveIt{}.csv'.format(SUFX))

policy_definitions = Sup.PolicyDefinitions()

# series to display on the cost-effectiveness plane
fixed_interval = Cls.SetOfScenarios(name='Static: Continuous',
                                    scenario_df=scenarioDfFixedPeriodic,
                                    color='blue',
                                    marker='o',
                                    conditions_on_variables=policy_definitions.FixedIntervalVarConditions,
                                    if_find_frontier=False,
                                    if_show_fitted_curve=True,
                                    labels_shift_x=0.01,
                                    labels_shift_y=0.01)

periodic = Cls.SetOfScenarios(name='Static: Periodic',
                              scenario_df=scenarioDfFixedPeriodic,
                              color='purple',
Beispiel #5
0
import SimPy.SensitivityAnalysis as SA
import SimPy.InOutFunctions as IO
from apace import ScenariosClasses as Sce

scenario_keys = [
    'Base', '75% PTFU | No >1 FU | Drop % | No IPT',
    '75% PTFU | With >1 FU | Drop 15% | No IPT',
    '75% PTFU | No >1 FU | Drop % | With IPT',
    '75% PTFU | With >1 FU | Drop 15% | With IPT'
]

# data frame for scenario analysis
scenario_df = Sce.ScenarioDataFrame('csv_files\TBScenarios.csv')

# read parameter samples
parameter_values = IO.read_csv_cols_to_dictionary(
    file_name='csv_files/SampledParams.csv',
    delimiter=',',
    if_convert_float=True)

# create a dictionaries of DALYs and cost
dict_DALY = {}
dict_cost = {}
for key in scenario_keys:
    dict_DALY[key] = scenario_df.scenarios[key].outcomes['DALY']
    dict_cost[key] = scenario_df.scenarios[key].outcomes['Total Cost']

# create dictionaries for dDALYS and dCost
dict_dDALY = {}
dict_dCost = {}
for key in scenario_keys:
Beispiel #6
0
    def __init__(self, if_spatial=False):

        # conditions of variables to define scenarios to display
        # on each series of cost-effectiveness plane
        self.FixedIntervalVarConditions = [
            Cls.ConditionOnVariable('Decision Rule',
                                    0,
                                    0,
                                    if_included_in_label=False),
            Cls.ConditionOnVariable(
                'Duration of Social Distancing',
                0,
                110,  # 200
                if_included_in_label=True,
                label_format='{:.0f}'),
            # Cls.VariableCondition(' Time of lifting social distancing', 1, 1,
            #                       if_included_in_label=False),
            # Cls.VariableCondition('Switch threshold if social distancing is off',
            #                       DS_TESTS, DS_TESTS,
            #                       if_included_in_label=False),
            # Cls.VariableCondition('Switch threshold if social distancing is on',
            #                       DS_TESTS, DS_TESTS,
            #                       if_included_in_label=False)
        ]
        self.ICUInfVarConditions = [
            Cls.ConditionOnVariable('Decision Rule',
                                    2,
                                    2,
                                    if_included_in_label=False),
            Cls.ConditionOnVariable(
                '% I Switch threshold if social distancing is off',
                0,
                20000,  # 1, 5
                if_included_in_label=False,
                label_format='{:.0f}'),
            Cls.ConditionOnVariable(
                '% I Switch threshold if social distancing is on',
                0,
                20000,  # 0, 5
                if_included_in_label=False,
                label_format='{:.0f}'),
            Cls.ConditionOnVariable(
                'WTP',
                0,
                0,  # 0, 5
                if_included_in_label=False,
                label_format='{:.0f}'),
            # Cls.VariableCondition(' Time of lifting social distancing', 1, 1,
            #                       if_included_in_label=False),
            # Cls.VariableCondition('Switch threshold if social distancing is off',
            #                       DS_TESTS, DS_TESTS,
            #                       if_included_in_label=False),
            # Cls.VariableCondition('Switch threshold if social distancing is on',
            #                       DS_TESTS, DS_TESTS,
            #                       if_included_in_label=False)
        ]
        self.ICUInfOutcomeConditions = [
            Cls.ConditionOnOutcome(
                outcome_name='Average ratio: % served in ICU',
                minimum=0.4,
                maximum=1,
                if_included_in_label=True,
                label_format='{:.0%}'),
            Cls.ConditionOnOutcome(outcome_name='Number of Switches',
                                   minimum=0,
                                   maximum=100,
                                   if_included_in_label=False,
                                   label_format='{:.0f}')
        ]

        self.PeriodicVarConditions = [
            Cls.ConditionOnVariable('Decision Rule',
                                    1,
                                    1,
                                    if_included_in_label=False),
            Cls.ConditionOnVariable(
                'Periodicity (weeks)',  #2, 8,  # 1, 5
                values=[2, 4, 8],
                if_included_in_label=True,
                label_format='{:.0f}'),
            # Cls.VariableCondition(' Time of lifting social distancing', 1, 1,
            #                       if_included_in_label=False),
            # Cls.VariableCondition('Switch threshold if social distancing is off',
            #                       DS_TESTS, DS_TESTS,
            #                       if_included_in_label=False),
            # Cls.VariableCondition('Switch threshold if social distancing is on',
            #                       DS_TESTS, DS_TESTS,
            #                       if_included_in_label=False)
        ]
        self.AdaptiveItVarConditions = [
            Cls.ConditionOnVariable('Decision Rule',
                                    3,
                                    3,
                                    if_included_in_label=False),
            Cls.ConditionOnVariable(
                'WTP',  #0.01, 2,  # 1, 5
                values=[
                    0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.08, 0.1, 0.12, 0.13,
                    0.14
                ],
                if_included_in_label=True,
                label_format='{:.2f}'),
            # Cls.VariableCondition(' Time of lifting social distancing', 1, 1,
            #                       if_included_in_label=False),
            # Cls.VariableCondition('Switch threshold if social distancing is off',
            #                       DS_TESTS, DS_TESTS,
            #                       if_included_in_label=False),
            # Cls.VariableCondition('Switch threshold if social distancing is on',
            #                       DS_TESTS, DS_TESTS,
            #                       if_included_in_label=False)
        ]
        self.AdaptiveRVarConditions = [
            Cls.ConditionOnVariable('Decision Rule',
                                    2,
                                    2,
                                    if_included_in_label=False),
            Cls.ConditionOnVariable(
                'R_t Switch threshold if social distancing is off',
                1,
                5,
                if_included_in_label=False,
                label_format='{:.1f}'),
            Cls.ConditionOnVariable(
                'R_t Switch threshold if social distancing is on',
                0,
                5,
                if_included_in_label=False,
                label_format='{:.1f}'),
            # Cls.VariableCondition(' Time of lifting social distancing', 1, 1,
            #                       if_included_in_label=False),
            # Cls.VariableCondition('Switch threshold if social distancing is off',
            #                       DS_TESTS, DS_TESTS,
            #                       if_included_in_label=False),
            # Cls.VariableCondition('Switch threshold if social distancing is on',
            #                       DS_TESTS, DS_TESTS,
            #                       if_included_in_label=False)
        ]
def analyze_econ_eval(prob_uptake, prob_dropout):

    # find the name of this analysis
    analysis_name = 'U{:.{prec}f}% '.format(prob_uptake * 100, prec=0) \
                    + 'D{:.{prec}f}%'.format(prob_dropout * 100, prec=0)
    print('Results for:', analysis_name)

    # conditions of variables to define scenarios to display on the cost-effectiveness plane
    # here we want scenarios with
    # 'Prob {Tc+ | Tc}' = PROB,
    # 'Follow-Up (Tc+>1)' = any, and
    # 'IPT' = any
    varConditions = [
        Cls.ConditionOnVariable('Prob {Tc+ | Tc}',
                                minimum=prob_uptake,
                                maximum=prob_uptake,
                                if_included_in_label=False),
        Cls.ConditionOnVariable('Follow-Up (Tc+>1)',
                                minimum=0,
                                maximum=1,
                                if_included_in_label=True,
                                label_rules=[
                                  (0, 'First-year follow-up'),
                                  (1, 'Annual follow-up')]
                                ),
        Cls.ConditionOnVariable('Prob {Drop-Out in Tc+>1}',
                                values=(prob_dropout, 0),
                                if_included_in_label=False),
        Cls.ConditionOnVariable('IPT',
                                minimum=0,
                                maximum=1,
                                if_included_in_label=True,
                                label_rules=[
                                  (0, ''),
                                  (1, 'with 2°IPT')]
                                )
    ]

    # data frame of scenarios
    dfScenarios = Cls.ScenarioDataFrame(csv_file_name='csv_files\TBScenarios.csv')

    # series to display on the cost-effectiveness plane
    series = [
        Cls.SetOfScenarios(name='U{:.{prec}f}%'.format(prob_uptake * 100, prec=0)
                                +'-D{:.{prec}f}%'.format(prob_dropout * 100, prec=0),
                           scenario_df=dfScenarios,
                           color='#4D4D4D',  # '#808A87',
                           conditions_on_variables=varConditions,
                           if_find_frontier=True,
                           labels_shift_x=-0.04,
                           labels_shift_y=0.01)
    ]

    # populate series
    Cls.SetOfScenarios.populate_sets_of_scenarios(
        series,
        save_cea_results=True,
        colors_of_scenarios=colors,
        interval_type='p',
        effect_multiplier=1,
        cost_multiplier=1 / 1e3,
        wtp_range=[0, 1000])

    # CBA
    #del series[0].CBA.strategies[1:3]
    plt.rc('font', size=9)  # fontsize of texts
    series[0].CBA.plot_incremental_nmbs(
        title='',
        y_label='Incremental Net Monetary Benefit (Million $)',
        x_label='Cost-Effectiveness Threshold ($ per DALY Averted)',
        interval_type='n',
        transparency_lines=0.5,
        show_legend=True,
        y_range=(-1, 5),
        y_axis_multiplier=1/1000000, y_axis_decimal=1,
        figure_size=(4, 3.6),
        file_name='results/cea/NMB-' + analysis_name + '.pdf'
    )
    print('WTP range with the highest expected NMB:')
    print(series[0].CBA.find_optimal_switching_wtp_values(deci=1))

    series[0].CBA.plot_acceptability_curves(
        #title='Cost-Effectiveness Acceptability Curves',
        x_label='Cost-Effectiveness Threshold ($ per DALY Averted)',
        y_label='Probability of Resulting in the Highest NMB',
        y_range=None,
        fig_size=(4, 3.6),
        legends=['Base',
                 'First-year follow-up',
                 'Annual follow-up',
                 'First-year follow-up with limited 2°IPT',
                 'Annual follow-up with continuous 2°IPT'],
        file_name='results/cea/CEAC ' + analysis_name + '.pdf'
    )
    print('WTP range with the highest probability of being optimal:')
    # print(series[0].CBA.get_wtp_range_with_highest_prob_of_optimal())

    # print dCost, dEffect and cost-effectiveness ratio with respect to the base
    print('\nRelative cost to Base, Relative DALY to base, CER')
    print(series[0].CEA.get_dCost_dEffect_cer(interval_type='p',
                                              alpha=0.05,
                                              cost_digits=0, effect_digits=0, icer_digits=1,
                                              cost_multiplier=1, effect_multiplier=1))

    # plot both incremental NMB and CEAC
    plot_nmb_and_ceac(cba=series[0].CBA,
                      fig_size=(8, 3.5),
                      file_name='results\cea\INMB_CEAC-' + analysis_name + '.pdf')

    # plot cost-effectiveness figure
    plot_ce_figure(series=series, analysis_name=analysis_name)

    # pairwise
    # column titles
    titles = ['Base',
              'First-year follow-up',
              'Annual follow-up',
              'First-year follow-up\nwith limited 2°IPT',
              'Annual follow-up\nwith continuous 2°IPT']

    # plot
    series[0].CEA.plot_pairwise_ceas(
        figure_size=(7, 7),
        font_size=7,
        effect_label='DALY Averted (Thousands)',
        cost_label='Additional Cost (Thousand Dollars)',
        center_s=40,
        cloud_s=10,
        transparency=0.1,
        effect_multiplier=1/1000,
        cost_multiplier=1/1000,
        x_range=[-10, 20],
        y_range=[-2000, 2000],
        column_titles=titles,
        row_titles=titles,
        file_name='results\cea\pairwise-' + analysis_name + '.pdf'
    )