Exemplo n.º 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
    Path.plot_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'],
                           color_codes=['green', 'blue'])

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

    # graph histograms
    Hist.plot_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'],
                         color_codes=['green', 'blue'],
                         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 patient.stateMonitor.survivalTime is not None:
                self.survivalTimes.append(patient.stateMonitor.survivalTime)
            # time until AIDS
            if patient.stateMonitor.timeToAIDS is not None:
                self.timesToAIDS.append(patient.stateMonitor.timeToAIDS)
            # discounted cost and discounted utility
            self.costs.append(
                patient.stateMonitor.costUtilityMonitor.totalDiscountedCost)
            self.utilities.append(
                patient.stateMonitor.costUtilityMonitor.totalDiscountedUtility)

        # summary statistics
        self.statSurvivalTime = Stat.SummaryStat(name='Survival time',
                                                 data=self.survivalTimes)
        self.statTimeToAIDS = Stat.SummaryStat(name='Time until AIDS',
                                               data=self.timesToAIDS)
        self.statCost = Stat.SummaryStat(name='Discounted cost',
                                         data=self.costs)
        self.statUtility = Stat.SummaryStat(name='Discounted utility',
                                            data=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 draw_survival_curves_and_histograms(calibrated_model_no_drug,
                                        calibrated_model_with_drug):
    """ draws the histograms of average survival time
    :param calibrated_model_no_drug: calibrated model simulated when drug is not available
    :param calibrated_model_with_drug: calibrated model simulated when drug is available
    """

    # get survival curves of both treatments
    survival_curves = [
        calibrated_model_no_drug.multiCohorts.multiCohortOutcomes.
        survivalCurves, calibrated_model_with_drug.multiCohorts.
        multiCohortOutcomes.survivalCurves
    ]

    # graph survival curve
    Path.plot_sets_of_sample_paths(sets_of_sample_paths=survival_curves,
                                   title='Survival curve',
                                   x_label='Simulation time step',
                                   y_label='Number of alive patients',
                                   legends=['No Drug', 'With Drug'],
                                   color_codes=['blue', 'orange'],
                                   transparency=0.25)

    # histograms of average survival times
    set_of_survival_times = [
        calibrated_model_no_drug.multiCohorts.multiCohortOutcomes.
        meanSurvivalTimes, calibrated_model_with_drug.multiCohorts.
        multiCohortOutcomes.meanSurvivalTimes
    ]

    # graph histograms
    Hist.plot_histograms(data_sets=set_of_survival_times,
                         title='Histogram of average patient survival time',
                         x_label='Survival time',
                         y_label='Counts',
                         bin_width=0.5,
                         legends=['No Drug', 'With Drug'],
                         color_codes=['blue', 'orange'],
                         transparency=0.5,
                         x_range=[6, 20])
Exemplo n.º 4
0
def plot_survival_curves_and_histograms(sim_outcomes_none, sim_outcomes_anticoag):
    """ draws the survival curves and the histograms of time until HIV deaths
    :param sim_outcomes_none: outcomes of a cohort simulated under no therapy
    :param sim_outcomes_anticoag: outcomes of a cohort simulated under anticoagulation
    """

    # get survival curves of both treatments
    survival_curves = [
        sim_outcomes_none.nLivingPatients,
        sim_outcomes_anticoag.nLivingPatients
    ]

    # graph survival curve
    Path.plot_sample_paths(
        sample_paths=survival_curves,
        title='Survival curve',
        x_label='Simulation time step (year)',
        y_label='Number of alive patients',
        legends=['No Therapy', 'Anticoagulation'],
        color_codes=['red', 'blue']
    )

    # histograms of survival times
    set_of_strokes = [
        sim_outcomes_none.nStrokes,
        sim_outcomes_anticoag.nStrokes
    ]

    # graph histograms
    Hist.plot_histograms(
        data_sets=set_of_strokes,
        title='Histogram of number of strokes',
        x_label='Number of Strokes',
        y_label='Counts',
        bin_width=1,
        legends=['No Therapy', 'Anticoagulation'],
        color_codes=['red', 'blue'],
        transparency=0.5
    )
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
    Path.plot_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
    Hist.plot_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=['Mono Therapy', 'Combination Therapy'],
                         color_codes=['green', 'blue'],
                         transparency=0.5)
Exemplo n.º 6
0
def draw_survival_curves_and_histograms(cohort_no_drug, cohort_with_drug):
    """ draws the survival curves and the histograms of survival time
    :param cohort_no_drug: a cohort simulated when drug is not available
    :param cohort_with_drug: a cohort simulated when drug is available
    """

    # get survival curves of both treatments
    survival_curves = [
        cohort_no_drug.cohortOutcomes.nLivingPatients,
        cohort_with_drug.cohortOutcomes.nLivingPatients
    ]

    # graph survival curve
    Path.plot_sample_paths(sample_paths=survival_curves,
                           title='Survival curve',
                           x_label='Simulation time step',
                           y_label='Number of alive patients',
                           legends=['No Drug', 'With Drug'],
                           color_codes=['blue', 'orange'],
                           transparency=0.5)

    # histograms of survival times
    set_of_survival_times = [
        cohort_no_drug.cohortOutcomes.survivalTimes,
        cohort_with_drug.cohortOutcomes.survivalTimes
    ]

    # graph histograms
    Hist.plot_histograms(data_sets=set_of_survival_times,
                         title='Histogram of patient survival time',
                         x_label='Survival time',
                         y_label='Counts',
                         bin_width=2,
                         legends=['No Drug', 'With Drug'],
                         color_codes=['blue', 'orange'],
                         transparency=0.5)
Exemplo n.º 7
0
    def calculate_cohort_outcomes(self, initial_pop_size):
        """ calculates the cohort outcomes
        :param initial_pop_size: initial population size
        """
        self.statSurvivalTime = Stat.SummaryStat(name='Survival Time',
                                                 data=self.survivalTimes)
        self.statCost = Stat.SummaryStat(name='Discounted cost',
                                         data=self.costs)
        self.statUtility = Stat.SummaryStat(name='Discounted utility',
                                            data=self.utilities)
        self.statNumStrokes = Stat.SummaryStat(name='Total Number of Strokes',
                                               data=self.nStrokes)

        self.nLivingPatients = Path.PrevalencePathBatchUpdate(
            name='# of living patients',
            initial_size=initial_pop_size,
            times_of_changes=self.survivalTimes,
            increments=[-1] * len(self.survivalTimes))
Exemplo n.º 8
0
    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 AIDS
        for patient in simulated_patients:
            if patient.stateMonitor.survivalTime is not None:
                self.survivalTimes.append(patient.stateMonitor.survivalTime)
            if patient.stateMonitor.timeToAIDS is not None:
                self.timesToAIDS.append(patient.stateMonitor.timeToAIDS)

        # calculate mean survival time
        self.meanSurvivalTime = sum(self.survivalTimes) / len(
            self.survivalTimes)
        # calculate mean time to AIDS
        self.meanTimeToAIDS = sum(self.timesToAIDS) / len(self.timesToAIDS)

        # 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))
Exemplo n.º 9
0
    size=Sets.PRIOR_N)

# create multiple cohorts
multiCohort = Cls.MultiCohort(
    ids=range(Sets.PRIOR_N),
    pop_sizes=[Sets.SIM_POP_SIZE] * Sets.PRIOR_N,
    mortality_probs=mortality_samples  # [p1, p2, ....]
)

# simulate all cohorts
multiCohort.simulate(Sets.TIME_STEPS)

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

# plot the histogram of average survival time
Hist.plot_histogram(
    data=multiCohort.multiCohortOutcomes.meanSurvivalTimes,
    title='Histogram of Mean Survival Time',
    x_label='Mean Survival Time (Year)',
    y_label='Count',
    x_range=[2.5, 21.5],
    bin_width=0.5)

# create the histogram of the mortality probabilities
Hist.plot_histogram(
    data=mortality_samples,
Exemplo n.º 10
0
import SimPy.Plots.Histogram as Hist
import SimPy.Plots.SamplePaths as Path

# selected therapy
therapy = P.Therapies.COMBO

# create a cohort
myCohort = Cls.Cohort(id=1,
                      pop_size=D.POP_SIZE,
                      parameters=P.Parameters(therapy=therapy))

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

# plot the sample path (survival curve)
Path.plot_sample_path(sample_path=myCohort.cohortOutcomes.nLivingPatients,
                      title='Survival Curve',
                      x_label='Time-Step (Year)',
                      y_label='Number Survived')

# plot the histogram of survival times
Hist.plot_histogram(data=myCohort.cohortOutcomes.survivalTimes,
                    title='Histogram of Patient Survival Time',
                    x_label='Survival Time (Year)',
                    y_label='Count',
                    bin_width=1)

# print the outcomes of this simulated cohort
Support.print_outcomes(sim_outcomes=myCohort.cohortOutcomes,
                       therapy_name=therapy)
Exemplo n.º 11
0
import SimPy.Plots.SamplePaths as Path

# a sample path with initial size = 1
path1 = Path.IncidenceSamplePath('Path 1', delta_t=1, sim_rep=1)
# record the observations
path1.record_increment(1.2, 2)
path1.record_increment(2.3, 1)
path1.record_increment(5.1, 5)
path1.close(6)
# stats
print(path1.stat.get_mean())

# second sample path with initial size = 1
path2 = Path.IncidenceSamplePath('Path 2', delta_t=1, sim_rep=1)
# record the observations
path2.record_increment(0.5, 4)
path2.record_increment(1.8, 2)
path2.record_increment(5.5, 1)
path2.close(6)
# stats
print(path2.stat.get_mean())

# plot path 1 only
Path.plot_sample_path(
    sample_path=path1,
    title='Plotting a single sample path',
    x_label='Time Period',
    y_label='observed value',
    legend='Path 1',
    color_code='r',
    connect='line')
Exemplo n.º 12
0
from SimPy.Plots import SamplePaths as Path

# a sample path with initial size = 1
path1 = Path.PrevalenceSamplePath('Path 1', initial_size=1, sim_rep=1)
# record the observations
path1.record_increment(1.2, 2)
path1.record_increment(2.3, -1)
path1.record_increment(5.1, 0)

# second sample path with initial size = 1
path2 = Path.PrevalenceSamplePath('Path 2', initial_size=0, sim_rep=1)
# record the observations
path2.record_increment(0.5, 4)
path2.record_increment(1.8, -2)
path2.record_increment(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)
path4 = Path.PrevalencePathBatchUpdate('Path 4',
                                       0,
                                       times_of_changes=[0.5, 4, 4.5],
                                       increments=[2.5, 1, 1],
                                       sim_rep=1)

# stats
print(path1.stat.get_mean())