예제 #1
0
def plot_survival_curves_and_histograms(sim_outcomes_mono, sim_outcomes_combo):
    """ draws the survival curves and the histograms of time until HIV deaths
    :param sim_outcomes_mono: outcomes of a cohort simulated under mono therapy
    :param sim_outcomes_combo: outcomes of a cohort simulated under combination therapy
    """

    # get survival curves of both treatments
    survival_curves = [
        sim_outcomes_mono.nLivingPatients, sim_outcomes_combo.nLivingPatients
    ]

    # graph survival curve
    PathCls.graph_sample_paths(sample_paths=survival_curves,
                               title='Survival curve',
                               x_label='Simulation time step (year)',
                               y_label='Number of alive patients',
                               legends=['Mono Therapy', 'Combination Therapy'])

    # histograms of survival times
    set_of_survival_times = [
        sim_outcomes_mono.survivalTimes, sim_outcomes_combo.survivalTimes
    ]

    # graph histograms
    Figs.graph_histograms(data_sets=set_of_survival_times,
                          title='Histogram of patient survival time',
                          x_label='Survival time (year)',
                          y_label='Counts',
                          bin_width=1,
                          legends=['Mono Therapy', 'Combination Therapy'],
                          transparency=0.6)
예제 #2
0
def plot_survival_curves_and_histograms(sim_outcomes_NO, sim_outcomes_ASP):

    # get survival curves of both treatments
    survival_curves = [
        sim_outcomes_NO.nLivingPatients, sim_outcomes_ASP.nLivingPatients
    ]

    # graph survival curve
    PathCls.graph_sample_paths(sample_paths=survival_curves,
                               title='Survival curve',
                               x_label='Simulation time step (year)',
                               y_label='Number of alive patients',
                               legends=['No Therapy', 'Aspirin Therapy'])

    # histograms of survival times
    set_of_survival_times = [
        sim_outcomes_NO.survivalTimes, sim_outcomes_ASP.survivalTimes
    ]

    # graph histograms
    Figs.graph_histograms(data_sets=set_of_survival_times,
                          title='Histogram of patient survival time',
                          x_label='Survival time (year)',
                          y_label='Counts',
                          bin_width=1,
                          legends=['No Therapy', 'Aspirin Therapy'],
                          transparency=0.6)
    def extract_outcomes(self, simulated_patients):
        """ extracts outcomes of a simulated cohort
        :param simulated_patients: a list of simulated patients"""

        # record patient outcomes
        for patient in simulated_patients:
            # survival time
            if not (patient.stateMonitor.survivalTime is None):
                self.survivalTimes.append(patient.stateMonitor.survivalTime)

            # discounted cost and number of patients alive
            self.costs.append(
                patient.stateMonitor.costUtilityMonitor.totalDiscountedCost)
            self.numPatientsAlive.append(patient.stateMonitor.numAlive)
            # self.utilities.append(patient.stateMonitor.costUtilityMonitor.totalDiscountedUtility)

        # summary statistics
        self.statSurvivalTime = Stat.SummaryStat('Survival time',
                                                 self.survivalTimes)
        self.statCost = Stat.SummaryStat('Discounted cost', self.costs)
        self.statAlive = Stat.SummaryStat('Number of patients alive',
                                          self.numPatientsAlive)
        # self.statUtility = Stat.SummaryStat('Discounted utility', self.utilities)

        # survival curve
        self.nLivingPatients = Path.PrevalencePathBatchUpdate(
            name='# of living patients',
            initial_size=len(simulated_patients),
            times_of_changes=self.survivalTimes,
            increments=[-1] * len(self.survivalTimes))
    def extract_outcomes(self, simulated_patients):
        """ extracts outcomes of a simulated cohort
        :param simulated_patients: a list of simulated patients"""

        # record survival time and time until STROKES
        for patient in simulated_patients:
            if not (patient.stateMonitor.survivalTime is None):
                self.survivalTimes.append(patient.stateMonitor.survivalTime)
            if patient.stateMonitor.ifDevelopedSTROKES:
                self.timesToSTROKES.append(patient.stateMonitor.timeToSTROKES)
            if patient.stateMonitor.ifDevelopedSTROKES:
                self.Num_stroke.append(patient.stateMonitor.num_strokes)

        # calculate mean survival time
        self.meanSurvivalTime = sum(self.survivalTimes) / len(self.survivalTimes)
        # calculate mean time to STROKES
        self.meanTimeToSTROKES = sum(self.timesToSTROKES)/len(self.timesToSTROKES)
        # calculate mean number of STROKES
        self.MeanNumberSTROKES=sum(self.Num_stroke)/len(self.Num_stroke)

        # survival curve
        self.nLivingPatients = PathCls.PrevalencePathBatchUpdate(
            name='# of living patients',
            initial_size=len(simulated_patients),
            times_of_changes=self.survivalTimes,
            increments=[-1]*len(self.survivalTimes)
        )
예제 #5
0
def plot_survival_curves_and_histograms(multi_cohort_outcomes_mono, multi_cohort_outcomes_combo):
    """ plot the survival curves and the histograms of survival times
    :param multi_cohort_outcomes_mono: outcomes of a multi-cohort simulated under mono therapy
    :param multi_cohort_outcomes_combo: outcomes of a multi-cohort simulated under combination therapy
    """

    # get survival curves of both treatments
    sets_of_survival_curves = [
        multi_cohort_outcomes_mono.survivalCurves,
        multi_cohort_outcomes_combo.survivalCurves
    ]

    # graph survival curve
    PathCls.graph_sets_of_sample_paths(
        sets_of_sample_paths=sets_of_survival_curves,
        title='Survival Curves',
        x_label='Simulation Time Step (year)',
        y_label='Number of Patients Alive',
        legends=['Mono Therapy', 'Combination Therapy'],
        transparency=0.4,
        color_codes=['green', 'blue']
    )

    # histograms of survival times
    set_of_survival_times = [
        multi_cohort_outcomes_mono.meanSurvivalTimes,
        multi_cohort_outcomes_combo.meanSurvivalTimes
    ]

    # graph histograms
    Figs.graph_histograms(
        data_sets=set_of_survival_times,
        title='Histograms of Average Patient Survival Time',
        x_label='Survival Time (year)',
        y_label='Counts',
        bin_width=0.25,
        x_range=[5.25, 17.75],
        legends=['No Therapy', 'Aspirin Therapy'],
        color_codes=['green', 'blue'],
        transparency=0.5
    )
예제 #6
0
def plot_survival_curves_and_histograms(multi_cohort_outcomes_SOC, multi_cohort_outcomes_NSB):
    """ plot the survival curves and the histograms of survival times
    :param multi_cohort_outcomes_SOC: outcomes of a multi-cohort simulated under mono therapy
    :param multi_cohort_outcomes_NSB: outcomes of a multi-cohort simulated under combination therapy
    """

    # get survival curves of both treatments
    sets_of_survival_curves = [
        multi_cohort_outcomes_SOC.survivalCurves,
        multi_cohort_outcomes_NSB.survivalCurves
    ]

    # graph survival curve
    PathCls.graph_sets_of_sample_paths(
        sets_of_sample_paths=sets_of_survival_curves,
        title='Survival Curves',
        x_label='Simulation Time Step (week)',
        y_label='Number of Patients Alive',
        legends=['SOC Diagnostic', 'NSB Diagnostic'],
        transparency=0.4,
        color_codes=['green', 'blue']
    )
예제 #7
0
    def extract_outcomes(self, simulated_patients):
        for patient in simulated_patients:
            if not (patient.stateMonitor.survivalTime is None):
                self.survivalTimes.append(patient.stateMonitor.survivalTime)
            self.costs.append(
                patient.stateMonitor.costUtilityMonitor.totalDiscountedCost)
            self.utilities.append(
                patient.stateMonitor.costUtilityMonitor.totalDiscountedUtility)

        self.statSurvivalTime = Stat.SummaryStat('Survival time',
                                                 self.survivalTimes)
        self.statCost = Stat.SummaryStat('Discounted cost', self.costs)
        self.statUtility = Stat.SummaryStat('Discounted utility',
                                            self.utilities)

        self.nLivingPatients = Path.PrevalencePathBatchUpdate(
            name='# of living patients',
            initial_size=len(simulated_patients),
            times_of_changes=self.survivalTimes,
            increments=[-1] * len(self.survivalTimes))
예제 #8
0
    pop_size=D.POP_SIZE,
    parameters=P.ParametersFixed(diagnostic=P.Diagnostic.NSB))

# simulate the cohort over the specified time steps
myCohort_NSB.simulate(sim_length=D.SIM_LENGTH)

# print the outcomes of this simulated cohort
Support.print_outcomes(sim_outcomes=myCohort_NSB.cohortOutcomes,
                       diagnostic_name=P.Diagnostic.NSB)

# histograms of the simulated cohort
Support.print_histograms(sim_outcomes=myCohort_NSB.cohortOutcomes,
                         diagnostic_name=P.Diagnostic.NSB)

PathCls.graph_sample_path(sample_path=myCohort.cohortOutcomes.nLivingPatients,
                          title='Survival Curve (Standard of Care Diagnostic)',
                          x_label='Time-Step (Week)',
                          y_label='Number Survived')

PathCls.graph_sample_path(
    sample_path=myCohort_NSB.cohortOutcomes.nLivingPatients,
    title='Survival Curve (SOC + Urine LAM)',
    x_label='Time-Step (Week)',
    y_label='Number Survived')

survival_curves = [
    myCohort.cohortOutcomes.nLivingPatients,
    myCohort_NSB.cohortOutcomes.nLivingPatients
]

# graph survival curve
# graph survival curve
예제 #9
0
def print_histograms(sim_outcomes, diagnostic_name):
    # plot the sample path (survival curve)
    PathCls.graph_sample_path(sample_path=sim_outcomes.nLivingPatients,
                              title=f'Survival Curve {diagnostic_name}',
                              x_label='Time-Step (Week)',
                              y_label='Number Survived')

    # plot the histogram of survival times
    Figs.graph_histogram(
        data=sim_outcomes.survivalTimes,
        title=f'Histogram of Patient Survival Time {diagnostic_name}',
        x_label='Survival Time (Week)',
        y_label='Count',
        bin_width=1)

    # Figs.graph_histogram(
    #     data=sim_outcomes.timesINFECTEDtoHOSP_TBD,
    #     title=f'Histogram of INFECTED to HOSP_TBD {diagnostic_name}',
    #     x_label='Time (Week)',
    #     y_label='Count',
    #     bin_width=1)
    #
    # Figs.graph_histogram(
    #     data=sim_outcomes.timesINFECTEDtoHOSP_TBM,
    #     title=f'Histogram of INFECTED to HOSP_TBM {diagnostic_name}',
    #     x_label='Time (Week)',
    #     y_label='Count',
    #     bin_width=1)
    #
    # Figs.graph_histogram(
    #     data=sim_outcomes.timesINFECTEDtoDX_TBD,
    #     title=f'Histogram of INFECTED to DX_TBD {diagnostic_name}',
    #     x_label='Time (Week)',
    #     y_label='Count',
    #     bin_width=1)
    #
    # Figs.graph_histogram(
    #     data=sim_outcomes.timesINFECTEDtoCLEARED,
    #     title=f'Histogram of INFECTED to CLEARED {diagnostic_name}',
    #     x_label='Time (Week)',
    #     y_label='Count',
    #     bin_width=1)
    #
    # Figs.graph_histogram(
    #     data=sim_outcomes.timesCLEAREDtoDEAD,
    #     title=f'Histogram of CLEARED to DEAD {diagnostic_name}',
    #     x_label='Time (Week)',
    #     y_label='Count',
    #     bin_width=1)
    #
    # Figs.graph_histogram(
    #     data=sim_outcomes.timesHOSP_TBDtoDEAD,
    #     title=f'Histogram of HOSP_TBD to DEAD {diagnostic_name}',
    #     x_label='Time (Week)',
    #     y_label='Count',
    #     bin_width=1)
    #
    # Figs.graph_histogram(
    #     data=sim_outcomes.timesHOSP_TBDtoDX_TBD,
    #     title=f'Histogram of HOSP_TBD to DX_TBD {diagnostic_name}',
    #     x_label='Survival Time (Week)',
    #     y_label='Count',
    #     bin_width=1)
    #
    # Figs.graph_histogram(
    #     data=sim_outcomes.timesHOSP_TBMtoDEAD,
    #     title=f'Histogram of HOSP_TBM to DEAD {diagnostic_name}',
    #     x_label='Survival Time (Week)',
    #     y_label='Count',
    #     bin_width=1)
    #
    # Figs.graph_histogram(
    #     data=sim_outcomes.timesHOSP_TBMtoDX_TBM,
    #     title=f'Histogram of HOSP_TBM to DX_TBM {diagnostic_name}',
    #     x_label='Time (Week)',
    #     y_label='Count',
    #     bin_width=1)
    #
    # Figs.graph_histogram(
    #     data=sim_outcomes.timesDX_TBDtoDEAD,
    #     title=f'Histogram of DX_TBD to DEAD {diagnostic_name}',
    #     x_label='Time (Week)',
    #     y_label='Count',
    #     bin_width=1)
    #
    # Figs.graph_histogram(
    #     data=sim_outcomes.timesDX_TBDtoCLEARED,
    #     title=f'Histogram of DX_TBD to CLEARED {diagnostic_name}',
    #     x_label='Time (Week)',
    #     y_label='Count',
    #     bin_width=1)
    #
    # Figs.graph_histogram(
    #     data=sim_outcomes.timesDX_TBMtoDEAD,
    #     title=f'Histogram of DX_TBM to DEAD {diagnostic_name}',
    #     x_label='Time (Week)',
    #     y_label='Count',
    #     bin_width=1)
    #
    # Figs.graph_histogram(
    #     data=sim_outcomes.timesDX_TBMtoCLEARED,
    #     title=f'Histogram of DX_TBM to CLEARED {diagnostic_name}',
    #     x_label='Time (Week)',
    #     y_label='Count',
    #     bin_width=1)
    #
    # Figs.graph_histogram(
    #     data=sim_outcomes.timesINFECTED,
    #     title=f'Histogram of INFECTED {diagnostic_name}',
    #     x_label='Time (Week)',
    #     y_label='Count',
    #     bin_width=1)
    #
    # Figs.graph_histogram(
    #     data=sim_outcomes.timesHOSP_TBM,
    #     title=f'Histogram of HOSP_TBM {diagnostic_name}',
    #     x_label='Time (Week)',
    #     y_label='Count',
    #     bin_width=1)
    #
    # Figs.graph_histogram(
    #     data=sim_outcomes.timesHOSP_TBD,
    #     title=f'Histogram of HOSP_TBD {diagnostic_name}',
    #     x_label='Time (Week)',
    #     y_label='Count',
    #     bin_width=1)
    #
    # Figs.graph_histogram(
    #     data=sim_outcomes.timesDX_TBD,
    #     title=f'Histogram of DX_TBD {diagnostic_name}',
    #     x_label='Time (Week)',
    #     y_label='Count',
    #     bin_width=1)
    #
    # Figs.graph_histogram(
    #     data=sim_outcomes.timesDX_TBM,
    #     title=f'Histogram of DX_TBM {diagnostic_name}',
    #     x_label='Time (Week)',
    #     y_label='Count',
    #     bin_width=1)
    #
    # Figs.graph_histogram(
    #     data=sim_outcomes.timesCLEARED,
    #     title=f'Histogram of CLEARED {diagnostic_name}',
    #     x_label='Time (Week)',
    #     y_label='Count',
    #     bin_width=1)

    # Figs.graph_histogram(
    #     data=sim_outcomes.costs,
    #     title=f'Histogram of Cost {diagnostic_name}',
    #     x_label='Cost (Dollars)',
    #     y_label='Count',
    #     bin_width=1)

    Figs.graph_histogram(
        data=sim_outcomes.costsPresenting,
        title=f'Histogram of Cost (Patients Presenting) {diagnostic_name}',
        x_label='Cost (Dollars)',
        y_label='Count',
        bin_width=1)
예제 #10
0
from SimPy import SamplePathClasses as Path

# a sample path with initial size = 1
path1 = Path.PrevalencePathRealTimeUpdate('Path 1', 0, sim_rep=1)
# record the observations
path1.record(1.5, 2)
path1.record(2, -1)
path1.record(5, 0)

# second sample path with initial size = 1
path2 = Path.PrevalencePathRealTimeUpdate('Path 2', 0, sim_rep=1)
# record the observations
path2.record(0.5, 4)
path2.record(1.8, -2)
path2.record(5.5, 1)

# third sample path with initial size = 1
path3 = Path.PrevalencePathBatchUpdate('Path 3',
                                       0,
                                       times_of_changes=[1.5, 2, 5],
                                       increments=[2, -1, 0],
                                       sim_rep=1)

# plot path 1 only
Path.graph_sample_path(sample_path=path1,
                       title='Plotting a single sample path',
                       x_label='time',
                       y_label='observed value',
                       legend='Path 1',
                       color_code='r')
예제 #11
0
calibrated_model_SOC.simulate(
    num_of_simulated_cohorts=CalibSets.NUM_SIM_COHORTS,
    cohort_size=CalibSets.SIM_POP_SIZE,
    sim_length=CalibSets.SIM_LENGTH,
    diagnostic=P.Diagnostic.SOC)

calibrated_model_NSB.simulate(
    num_of_simulated_cohorts=CalibSets.NUM_SIM_COHORTS,
    cohort_size=CalibSets.SIM_POP_SIZE,
    sim_length=CalibSets.SIM_LENGTH,
    diagnostic=P.Diagnostic.NSB)

# plot the sample paths
Path.graph_sample_paths(sample_paths=calibrated_model_SOC.multiCohorts.
                        multiCohortOutcomes.survivalCurves,
                        title='Survival Curves',
                        x_label='Time (Week)',
                        y_label='Number Survived',
                        transparency=0.5)

Path.graph_sample_paths(sample_paths=calibrated_model_NSB.multiCohorts.
                        multiCohortOutcomes.survivalCurves,
                        title='Survival Curves',
                        x_label='Time (Week)',
                        y_label='Number Survived',
                        transparency=0.5)

# plot the histogram of mean survival time
# Fig.graph_histogram(
#     data=calibrated_model.multiCohorts.multiCohortOutcomes.meanSurvivalTimes,
#     title='Histogram of Mean Survival Time',
#     x_label='Mean Survival Time (Week)',
예제 #12
0
# selected therapy
therapy_none = P.Therapies.NO

# create a cohort
myCohort_0 = Cls.Cohort(id=0,
                      pop_size=D.POP_SIZE,
                      parameters=P.ParametersFixed(therapy=therapy_none))

# simulate the cohort over the specified time steps
myCohort_0.simulate(sim_length=D.SIM_LENGTH)

# plot the sample path (survival curve)
Path.graph_sample_path(
    sample_path=myCohort_0.cohortOutcomes.nLivingPatients,
    title='Survival Curvel for No Therapy',
    x_label='Time-Step (Year)',
    y_label='Number Survived')

# plot the histogram of survival times
Fig.graph_histogram(
    data=myCohort_0.cohortOutcomes.survivalTimes,
    title='Histogram of Patient Survival Times for No Therapy',
    x_label='Survival Time (Year)',
    y_label='Count',
    bin_width=1)

# print the outcomes of this simulated cohort
Support.print_outcomes(sim_outcomes=myCohort_0.cohortOutcomes,therapy_name=therapy_none)

    def extract_outcomes(self, simulated_patients):
        """ extracts outcomes of a simulated cohort
        :param simulated_patients: a list of simulated patients"""

        # record survival time
        for patient in simulated_patients:
            # survival time
            if not (patient.stateMonitor.survivalTime is None):
                self.survivalTimes.append(patient.stateMonitor.survivalTime)

            # USE THIS SECTION IF NO INFORMATION ABOUT TIMES; USE THE BELOW SECTION IF WANT INFO ON TIMES
            if patient.stateMonitor.ifHOSP_TBD:
                self.nHOSP_TBD += 1
            if patient.stateMonitor.ifHOSP_TBM:
                self.nHOSP_TBM += 1
            if patient.stateMonitor.ifDX_TBD:
                self.nDX_TBD += 1
            if patient.stateMonitor.ifDX_TBM:
                self.nDX_TBM += 1
            if patient.stateMonitor.ifCLEARED:
                self.nCLEARED += 1
            if patient.stateMonitor.ifDEAD:
                self.nDEAD += 1

            # USE THIS SECTION IF WANT INFORMATION ABOUT TIME FOR EACH TRANSITION; USE ABOVE IF DON'T WANT
            # if patient.stateMonitor.ifHOSP_TBM:
            #     self.timesINFECTEDtoHOSP_TBM.append(patient.stateMonitor.timeINFECTEDtoHOSP_TBM)
            #     self.nHOSP_TBM += 1
            # if patient.stateMonitor.ifHOSP_TBD:
            #     self.timesINFECTEDtoHOSP_TBD.append(patient.stateMonitor.timeINFECTEDtoHOSP_TBD)
            #     self.nHOSP_TBD += 1
            # if patient.stateMonitor.ifDX_TBM:
            #     self.timesHOSP_TBMtoDX_TBM.append(patient.stateMonitor.timeHOSP_TBMtoDX_TBM)
            #     self.nDX_TBM += 1
            # if patient.stateMonitor.ifDX_TBD and patient.stateMonitor.ifHOSP_TBD:
            #     self.timesHOSP_TBDtoDX_TBD.append(patient.stateMonitor.timeHOSP_TBDtoDX_TBD)
            #     self.nDX_TBD += 1
            # if patient.stateMonitor.ifDX_TBD and (patient.stateMonitor.ifHOSP_TBD is False):  # and \
            #         # (patient.stateMonitor.ifHOSP_TBD is False) and (patient.stateMonitor.ifDEAD is False):
            #     self.timesINFECTEDtoDX_TBD.append(patient.stateMonitor.timeINFECTEDtoDX_TBD)
            #     self.nDX_TBD += 1
            # if patient.stateMonitor.ifCLEARED and patient.stateMonitor.ifDX_TBD:
            #     self.timesDX_TBDtoCLEARED.append(patient.stateMonitor.timeDX_TBDtoCLEARED)
            #     self.nCLEARED += 1
            # if patient.stateMonitor.ifCLEARED and patient.stateMonitor.ifDX_TBM:
            #     self.timesDX_TBMtoCLEARED.append(patient.stateMonitor.timeDX_TBMtoCLEARED)
            #     self.nCLEARED += 1
            # if patient.stateMonitor.ifCLEARED and (patient.stateMonitor.ifDX_TBD is False) and \
            #         (patient.stateMonitor.ifDX_TBM is False):
            #     self.timesINFECTEDtoCLEARED.append(patient.stateMonitor.timeINFECTEDtoCLEARED)
            #     self.nCLEARED += 1
            # # times from HOSP_TBM to DEAD
            # if patient.stateMonitor.ifDEAD and patient.stateMonitor.ifHOSP_TBM and \
            #         (patient.stateMonitor.ifCLEARED is False) and (patient.stateMonitor.ifHOSP_TBD is False) and \
            #         (patient.stateMonitor.ifDX_TBD is False) and (patient.stateMonitor.ifDX_TBM is False):
            #     self.timesHOSP_TBMtoDEAD.append(patient.stateMonitor.timeHOSP_TBMtoDEAD)
            #     self.nDEAD += 1
            # # times from HOSP_TBD to DEAD
            # if patient.stateMonitor.ifDEAD and patient.stateMonitor.ifHOSP_TBD and \
            #         (patient.stateMonitor.ifCLEARED is False) and (patient.stateMonitor.ifHOSP_TBM is False) and \
            #         (patient.stateMonitor.ifDX_TBM is False) and (patient.stateMonitor.ifDX_TBD is False):
            #     self.timesHOSP_TBDtoDEAD.append(patient.stateMonitor.timeHOSP_TBDtoDEAD)
            #     self.nDEAD += 1
            # # get rid of cleared and the two hosps
            # if patient.stateMonitor.ifDEAD and patient.stateMonitor.ifDX_TBM and \
            #         (patient.stateMonitor.ifCLEARED is False) and (patient.stateMonitor.timeHOSP_TBMtoDEAD is None) and\
            #         (patient.stateMonitor.ifHOSP_TBD is False) and (patient.stateMonitor.ifDX_TBD is False):
            #     self.timesDX_TBMtoDEAD.append(patient.stateMonitor.timeDX_TBMtoDEAD)
            #     self.nDEAD += 1
            # if patient.stateMonitor.ifDEAD and patient.stateMonitor.ifDX_TBD and \
            #         (patient.stateMonitor.ifCLEARED is False) and (patient.stateMonitor.timeHOSP_TBDtoDEAD is None) and\
            #         (patient.stateMonitor.ifHOSP_TBM is False) and (patient.stateMonitor.ifDX_TBM is False):
            #     self.timesDX_TBDtoDEAD.append(patient.stateMonitor.timeDX_TBDtoDEAD)
            #     self.nDEAD += 1
            # if patient.stateMonitor.ifDEAD and patient.stateMonitor.ifCLEARED and \
            #         (patient.stateMonitor.timeHOSP_TBMtoDEAD is None) and (patient.stateMonitor.timeHOSP_TBDtoDEAD is None) and \
            #         (patient.stateMonitor.timeDX_TBMtoDEAD is None) and (patient.stateMonitor.timeDX_TBDtoDEAD is None):
            #     self.timesCLEAREDtoDEAD.append(patient.stateMonitor.timeCLEAREDtoDEAD)
            #     self.nDEAD += 1

            # discounted cost and discounted utility
            self.costs.append(
                patient.stateMonitor.costUtilityMonitor.totalDiscountedCost)
            # self.utilities.append(patient.stateMonitor.costUtilityMonitor.totalDiscountedUtility)

            # discounted cost of all the patients who present to healthcare
            if not patient.stateMonitor.ifINFECTEDtoCLEARED:
                self.costsPresenting.append(
                    patient.stateMonitor.costUtilityMonitor.totalDiscountedCost
                )
                if patient.stateMonitor.survivalTime is None:
                    self.listYLLPresenting.append(0)
                else:
                    self.listYLLPresenting.append(
                        62.77 - (patient.stateMonitor.survivalTime / 52))
                if patient.stateMonitor.mortality56Day:
                    self.nMortality56Day += 1

            # total YLL due to TB infection
            if not patient.stateMonitor.ifCLEARED:
                if not (patient.stateMonitor.survivalTime is None):
                    self.totalYLL += 62.77 - (
                        patient.stateMonitor.survivalTime / 52)
                    self.listYLL.append(62.77 -
                                        (patient.stateMonitor.survivalTime /
                                         52))
                else:
                    self.listYLL.append(0)

            if patient.stateMonitor.mortality2Months:
                self.nMortality2Months += 1
            if patient.stateMonitor.mortality2Years:
                self.nMortality2Years += 1
            if patient.stateMonitor.mortality5Years:
                self.nMortality5Years += 1
            if patient.stateMonitor.mortality1Year:
                self.nMortality1Year += 1

        # Gather Data
        self.nHospitalized = self.nHOSP_TBD + self.nHOSP_TBM
        self.mortality56Day = self.nMortality56Day / D.POP_SIZE
        self.mortality2Months = self.nMortality2Months / D.POP_SIZE
        self.mortality1Year = self.nMortality1Year / D.POP_SIZE
        self.mortality2Years = self.nMortality2Years / D.POP_SIZE
        self.mortality5Years = self.nMortality5Years / D.POP_SIZE

        # self.timesINFECTED = self.timesINFECTEDtoCLEARED + self.timesINFECTEDtoDX_TBD + self.timesINFECTEDtoHOSP_TBM + \
        #     self.timesINFECTEDtoHOSP_TBD
        # self.timesHOSP_TBD = self.timesHOSP_TBDtoDEAD + self.timesHOSP_TBDtoDX_TBD
        # self.timesHOSP_TBM = self.timesHOSP_TBMtoDEAD + self.timesHOSP_TBMtoDX_TBM
        # self.timesDX_TBM = self.timesDX_TBMtoCLEARED + self.timesDX_TBMtoDEAD
        # self.timesDX_TBD = self.timesDX_TBDtoCLEARED + self.timesDX_TBDtoDEAD
        # self.timesCLEARED = self.timesCLEAREDtoDEAD

        # Summary Statistics
        self.statSurvivalTime = Stat.SummaryStat('Survival time',
                                                 self.survivalTimes)

        # self.statTimeINFECTEDtoHOSP_TBD = Stat.SummaryStat('Infected to HOSP_TBD', self.timesINFECTEDtoHOSP_TBD)
        # self.statTimeINFECTEDtoHOSP_TBM = Stat.SummaryStat('Infected to HOSP_TBM', self.timesINFECTEDtoHOSP_TBM)
        # self.statTimeINFECTEDtoDX_TBD = Stat.SummaryStat('Infected to DX_TBD', self.timesINFECTEDtoDX_TBD)
        # self.statTimeINFECTEDtoCLEARED = Stat.SummaryStat('Infected to Cleared', self.timesINFECTEDtoCLEARED)
        # self.statTimeCLEAREDtoDEAD = Stat.SummaryStat('Cleared to Dead', self.timesCLEAREDtoDEAD)
        # self.statTimeHOSP_TBDtoDEAD = Stat.SummaryStat('HOSP_TBD to Dead', self.timesHOSP_TBDtoDEAD)
        # self.statTimeHOSP_TBDtoDX_TBD = Stat.SummaryStat('HOSP_TBD to DX_TBD', self.timesHOSP_TBDtoDX_TBD)
        # self.statTimeHOSP_TBMtoDEAD = Stat.SummaryStat('HOSP_TBM to DEAD', self.timesHOSP_TBMtoDEAD)
        # self.statTimeHOSP_TBMtoDX_TBM = Stat.SummaryStat('HOSP_TBM to DX_TBM', self.timesHOSP_TBMtoDX_TBM)
        # self.statTimeDX_TBDtoDEAD = Stat.SummaryStat('DX_TBD to Dead', self.timesDX_TBDtoDEAD)
        # self.statTimeDX_TBDtoCLEARED = Stat.SummaryStat('DX_TBD to Cleared', self.timesDX_TBDtoCLEARED)
        # self.statTimeDX_TBMtoDEAD = Stat.SummaryStat('DX_TBM to Dead', self.timesDX_TBMtoDEAD)
        # self.statTimeDX_TBMtoCLEARED = Stat.SummaryStat('DX_TBM to Cleared', self.timesDX_TBMtoCLEARED)
        #
        # self.statTimesINFECTED = Stat.SummaryStat('Infected', self.timesINFECTED)
        # self.statTimesHOSP_TBM = Stat.SummaryStat('HOSP_TBM', self.timesHOSP_TBM)
        # self.statTimesHOSP_TBD = Stat.SummaryStat('HOSP_TBD', self.timesHOSP_TBD)
        # self.statTimesDX_TBD = Stat.SummaryStat('DX_TBD', self.timesDX_TBD)
        # self.statTimesDX_TBM = Stat.SummaryStat('DX_TBM', self.timesDX_TBM)
        # self.statTimesCLEARED = Stat.SummaryStat('Cleared', self.timesCLEARED)

        self.statCost = Stat.SummaryStat('Discounted cost', self.costs)
        # self.statCostPresenting = Stat.SummaryStat('Discounted cost (Presenting)', self.costsPresenting)
        # self.statUtility = Stat.SummaryStat('Discounted utility', self.utilities)

        # survival curve
        self.nLivingPatients = Path.PrevalencePathBatchUpdate(
            name='# of living patients',
            initial_size=len(simulated_patients),
            times_of_changes=self.survivalTimes,
            increments=[-1] * len(self.survivalTimes))
예제 #14
0
import SimPy.RandomVariantGenerators as RVGs
import SimPy.SamplePathClasses as Path
import SimPy.FigureSupport as Fig

# create multiple cohort
multiCohort = Cls.MultiCohort(
    ids=range(D.N_COHORTS),
    pop_size=D.POP_SIZE,
    parameters=P.ParametersFixed(diagnostic=P.Diagnostic.SOC))

multiCohort.simulate(sim_length=D.SIM_LENGTH)

# plot the sample paths
Path.graph_sample_paths(
    sample_paths=multiCohort.multiCohortOutcomes.survivalCurves,
    title='Survival Curves',
    x_label='Time-Step (Week)',
    y_label='Number Survived',
    transparency=0.5)

# plot the histogram of average survival time
Fig.graph_histogram(data=multiCohort.multiCohortOutcomes.meanSurvivalTimes,
                    title='Histogram of Mean Survival Time',
                    x_label='Mean Survival Time (Week)',
                    y_label='Count')

# print the outcomes of this simulated cohort
Support.print_outcomes(multi_cohort_outcomes=multiCohort.multiCohortOutcomes,
                       diagnostic=P.Diagnostic.SOC)

# create multiple cohort
multiCohort_NSB = Cls.MultiCohort(