def test_upper_bounds(self): highBPPerson = Person( age=75, gender=0, raceEthnicity=1, sbp=500, ldl=90, trig=150, dbp=80, a1c=6.5, hdl=50, totChol=210, bmi=22, waist=50, anyPhysicalActivity=0, education=Education.COLLEGEGRADUATE, smokingStatus=1, alcohol=AlcoholCategory.NONE, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, creatinine=0, initializeAfib=initializeAfib, ) highBPPerson.advance_risk_factors(self._risk_model_repository) self.assertEqual(300, highBPPerson._sbp[-1])
def setUp(self): self._test_person = Person( age=75, gender=0, raceEthnicity=1, sbp=140, dbp=80, a1c=6.5, hdl=50, totChol=210, ldl=90, trig=150, bmi=22, waist=50, anyPhysicalActivity=0, education=Education.COLLEGEGRADUATE, smokingStatus=1, alcohol=AlcoholCategory.NONE, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, creatinine=0, initializeAfib=initializeAfib, ) self._risk_model_repository = TestRiskModelRepository()
class TestNHANESLinearRiskFactorModel(unittest.TestCase): def setUp(self): self._test_person = Person( age=75, gender=0, raceEthnicity=1, sbp=140, dbp=80, a1c=6.5, hdl=50, totChol=210, ldl=90, trig=150, bmi=22, waist=50, anyPhysicalActivity=0, education=Education.COLLEGEGRADUATE, smokingStatus=1, alcohol=AlcoholCategory.NONE, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, creatinine=0, initializeAfib=initializeAfib, ) self._risk_model_repository = TestRiskModelRepository() def test_sbp_model(self): self._test_person.advance_risk_factors(self._risk_model_repository) expectedSBP = 75 * 1 + 140 * 0.5 + 80 self.assertEqual(expectedSBP, self._test_person._sbp[-1]) def test_upper_bounds(self): highBPPerson = Person( age=75, gender=0, raceEthnicity=1, sbp=500, ldl=90, trig=150, dbp=80, a1c=6.5, hdl=50, totChol=210, bmi=22, waist=50, anyPhysicalActivity=0, education=Education.COLLEGEGRADUATE, smokingStatus=1, alcohol=AlcoholCategory.NONE, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, creatinine=0, initializeAfib=initializeAfib, ) highBPPerson.advance_risk_factors(self._risk_model_repository) self.assertEqual(300, highBPPerson._sbp[-1])
def setUp(self): self.joe = Person(42, NHANESGender.MALE, NHANESRaceEthnicity.NON_HISPANIC_BLACK, 140, 90, 5.5, 50, 200, 25, 90, 150, 45, 0, Education.COLLEGEGRADUATE, SmokingStatus.NEVER, AlcoholCategory.NONE, 0, 0, 0, initializeAFib) self._always_positive_repository = AlwaysPositiveOutcomeRepository() self._always_negative_repository = AlwaysNegativeOutcomeRepository() self.cvDeterminer = CVOutcomeDetermination( self._always_positive_repository)
def setUp(self): self.oldJoe = Person( age=60, gender=NHANESGender.MALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_BLACK, sbp=140, dbp=90, a1c=5.5, hdl=50, totChol=200, bmi=25, ldl=90, trig=150, waist=45, anyPhysicalActivity=0, education=Education.COLLEGEGRADUATE, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.NONE, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, creatinine=0, initializeAfib=initializeAFib, ) self.youngJoe = Person( age=40, gender=NHANESGender.MALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_BLACK, sbp=140, dbp=90, a1c=5.5, hdl=50, totChol=200, bmi=25, ldl=90, trig=150, waist=45, anyPhysicalActivity=0, education=Education.COLLEGEGRADUATE, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.NONE, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, creatinine=0, initializeAfib=initializeAFib, )
def setUp(self): self.joe = Person( 42, NHANESGender.MALE, NHANESRaceEthnicity.NON_HISPANIC_BLACK, 140, 90, 5.5, 50, 200, 25, 90, 150, 70, 0, Education.COLLEGEGRADUATE, SmokingStatus.NEVER, AlcoholCategory.NONE, 0, 0, 0, 0, initializeAFib, selfReportStrokeAge=None, selfReportMIAge=None, dfIndex=1, diedBy2015=0, )
def generate_starting_mean_patient(self): df = self.get_people_initial_state_as_dataframe() return Person( age=int(round(df.age.mean())), gender=NHANESGender(df.gender.mode()), raceEthnicity=NHANESRaceEthnicity(df.raceEthnicity.mode()), sbp=df.sbp.mean(), dbp=df.dbp.mean(), a1c=df.a1c.mean(), hdl=df.hdl.mean(), totChol=df.totChol.mean(), bmi=df.bmi.mean(), ldl=df.ldl.mean(), trig=df.trig.mean(), waist=df.waist.mean(), anyPhysicalActivity=df.anyPhysicalActivity.mode(), education=Education(df.education.mode()), smokingStatus=SmokingStatus(df.smokingStatus.mode()), antiHypertensiveCount=int(round(df.antiHypetensiveCount().mean())), statin=df.statin.mode(), otherLipidLoweringMedicationCount=int( round(df.otherLipidLoweringMedicationCount.mean())), initializeAfib=(lambda _: False), selfReportStrokeAge=None, selfReportMIAge=None, randomEffects=self._outcome_model_repository.get_random_effects(), )
def build_person(x, outcome_model_repository): return Person( age=x.age, gender=NHANESGender(int(x.gender)), raceEthnicity=NHANESRaceEthnicity(int(x.raceEthnicity)), sbp=x.meanSBP, dbp=x.meanDBP, a1c=x.a1c, hdl=x.hdl, ldl=x.ldl, trig=x.trig, totChol=x.tot_chol, bmi=x.bmi, waist=x.waist, anyPhysicalActivity=x.anyPhysicalActivity, smokingStatus=SmokingStatus(int(x.smokingStatus)), alcohol=AlcoholCategory.get_category_for_consumption(x.alcoholPerWeek), education=Education(int(x.education)), antiHypertensiveCount=x.antiHypertensive, statin=x.statin, otherLipidLoweringMedicationCount=x.otherLipidLowering, creatinine=x.serumCreatinine, initializeAfib=initializeAFib, initializationRepository=InitializationRepository(), selfReportStrokeAge=x.selfReportStrokeAge, selfReportMIAge=np.random.randint(18, x.age) if x.selfReportMIAge == 99999 else x.selfReportMIAge, randomEffects=outcome_model_repository.get_random_effects(), dfIndex=x.index, diedBy2015=x.diedBy2015 == True, )
def getPerson(self, age=65): return Person( age=age, gender=0, raceEthnicity=1, sbp=140, dbp=80, a1c=6.5, hdl=50, totChol=210, ldl=90, trig=150, bmi=22, waist=50, anyPhysicalActivity=0, education=Education.COLLEGEGRADUATE, smokingStatus=1, alcohol=0, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, creatinine=0, initializeAfib=TestQALYAssignment.initializeAfib, initializationRepository=InitializationRepository(), )
def get_or_init_population_dataframe(cls): if VectorizedTestFixture._population_dataframe is None: test_person = Person( age=71, gender=NHANESGender.MALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_WHITE, sbp=144.667, dbp=52.6667, a1c=9.5, hdl=34, totChol=191, bmi=30.05, ldl=110.0, trig=128, waist=45, anyPhysicalActivity=0, education=Education.COLLEGEGRADUATE, smokingStatus=SmokingStatus.FORMER, alcohol=AlcoholCategory.NONE, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, creatinine=0.6, initializeAfib=(lambda _: None), randomEffects={"gcp": 0}, ) base_gcp = GCPModel().get_risk_for_person(test_person) test_person._gcp.append([base_gcp]) VectorizedTestFixture._population_dataframe = init_vectorized_population_dataframe( [test_person]) return VectorizedTestFixture._population_dataframe
def build_person(x): return Person(age=x.age, gender=NHANESGender(int(x.gender)), raceEthnicity=NHANESRaceEthnicity(int(x.raceEthnicity)), sbp=x.meanSBP, dbp=x.meanDBP, a1c=x.a1c, hdl=x.hdl, ldl=x.ldl, trig=x.trig, totChol=x.tot_chol, bmi=x.bmi, waist=x.waist, anyPhysicalActivity=x.anyPhysicalActivity, smokingStatus=SmokingStatus(int(x.smokingStatus)), alcohol=AlcoholCategory.get_category_for_consumption( x.alcoholPerWeek), education=Education(int(x.education)), antiHypertensiveCount=x.antiHypertensive, statin=x.statin, otherLipidLoweringMedicationCount=x.otherLipidLowering, initializeAfib=initializeAFib, selfReportStrokeAge=x.selfReportStrokeAge, selfReportMIAge=x.selfReportMIAge, dfIndex=x.index, diedBy2015=x.diedBy2015)
def setUp(self): self.imputed_dataset_first_person = Person(71, NHANESGender.MALE, NHANESRaceEthnicity.NON_HISPANIC_WHITE, 144.667, 52.6667, 9.5, 34, 191, 30.05, 110.0, 128, 45, 0, Education.COLLEGEGRADUATE, SmokingStatus.FORMER, AlcoholCategory.NONE, 0, 0, 0, initializeAFib) model_spec = load_model_spec("nhanesMortalityModel") self.model = StatsModelCoxModel(CoxRegressionModel(**model_spec))
def setUp(self): self.baselineSBP = 140 self.baselineDBP = 80 self._test_person = Person( age=75, gender=0, raceEthnicity=1, sbp=self.baselineSBP, dbp=self.baselineDBP, a1c=6.5, hdl=50, totChol=210, ldl=90, trig=150, bmi=22, waist=50, anyPhysicalActivity=0, education=Education.COLLEGEGRADUATE, smokingStatus=1, alcohol=0, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, initializeAfib=TestTreatmentStrategy.initializeAfib) self._risk_model_repository = TestRiskModelRepository() # setup so that the SBP always stays the same self._risk_model_repository._repository['sbp']._params['age'] = 0 self._risk_model_repository._repository['sbp']._params['sbp'] = 1.0 self._risk_model_repository._repository['sbp']._params['intercept'] = 0 self._risk_model_repository._repository['dbp']._params['age'] = 0 self._risk_model_repository._repository['dbp']._params['dbp'] = 1.0 self._risk_model_repository._repository['dbp']._params['sbp'] = 0 self._risk_model_repository._repository['dbp']._params['intercept'] = 0 # setup so that the anti-hypertensive count stays at zero self._risk_model_repository._repository[ 'antiHypertensiveCount']._params['age'] = 0 self._risk_model_repository._repository[ 'antiHypertensiveCount']._params['sbp'] = 0 self._risk_model_repository._repository[ 'antiHypertensiveCount']._params['intercept'] = 0
def setUp(self): self.joe = Person( 42, NHANESGender.MALE, NHANESRaceEthnicity.NON_HISPANIC_BLACK, 140, 90, 5.5, 50, 200, 25, 90, 150, 45, 0, Education.COLLEGEGRADUATE, SmokingStatus.NEVER, AlcoholCategory.NONE, 0, 0, 0, 0, initializeAFib, ) self.joe_with_mi = copy.deepcopy(self.joe) self.joe_with_mi.add_outcome_event(Outcome(OutcomeType.MI, False)) self.joe_with_stroke = copy.deepcopy(self.joe) self.joe_with_stroke.add_outcome_event(Outcome(OutcomeType.STROKE, False)) self._population_dataframe = init_vectorized_population_dataframe( [self.joe, self.joe_with_mi, self.joe_with_stroke], with_base_gcp=True, ) self._always_positive_repository = AlwaysPositiveOutcomeRepository() self._always_negative_repository = AlwaysNegativeOutcomeRepository() self.cvDeterminer = CVOutcomeDetermination(self._always_positive_repository)
def get_risk_for_person(self, person, years=1, vectorized=False, test=False): random_effect = 0 if not vectorized: random_effect = person._randomEffects[ "gcp"] if "gcp" in person._randomEffects else 0 residual = 0 if test else np.random.normal(0.38, 6.99) linPred = 0 if vectorized: linPred = self.calc_linear_predictor_for_patient_characteristics( yearsInSim=person.totalYearsInSim, raceEthnicity=person.raceEthnicity, gender=person.gender, baseAge=person.baseAge, education=person.education, alcohol=person.alcoholPerWeek, smokingStatus=person.smokingStatus, bmi=person.bmi, waist=person.waist, totChol=person.totChol, meanSBP=person.meanSbp, anyAntiHpertensive=(person.antiHypertensiveCount > 0), fastingGlucose=Person.convert_a1c_to_fasting_glucose( person.a1c), physicalActivity=person.anyPhysicalActivity, afib=person.afib, ) else: linPred = self.calc_linear_predictor_for_patient_characteristics( yearsInSim=person.years_in_simulation(), raceEthnicity=person._raceEthnicity, gender=person._gender, baseAge=person._age[0], education=person._education, alcohol=person._alcoholPerWeek[-1], smokingStatus=person._smokingStatus, bmi=person._bmi[-1], waist=person._waist[-1], totChol=person._totChol[-1], meanSBP=np.array(person._sbp).mean(), anyAntiHpertensive=(person._antiHypertensiveCount[-1] > 0), fastingGlucose=person.get_fasting_glucose(not test), physicalActivity=person._anyPhysicalActivity[-1], afib=person._afib[-1], ) return linPred + random_effect + residual
def getPerson(self, baselineSBP=140, baselineDBP=80): return Person( age=75, gender=0, raceEthnicity=1, sbp=baselineSBP, dbp=baselineDBP, a1c=6.5, hdl=50, totChol=210, ldl=90, trig=150, bmi=22, waist=50, anyPhysicalActivity=0, education=Education.COLLEGEGRADUATE, smokingStatus=1, alcohol=0, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, creatinine=0.0, initializeAfib=TestTreatmentStrategy.initializeAfib, )
def setUp(self): self._test_case_one = Person( age=65 - 0.828576318 * 10, gender=NHANESGender.FEMALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_WHITE, sbp=120 + 0.45 * 10, dbp=80, # guessingon the centering standard for glucose...may have to check a1c=Person.convert_fasting_glucose_to_a1c(100 - 1.1 * 10), hdl=50, totChol=127 - 3.64 * 10, ldl=90, trig=150, bmi=26.6 + 15.30517532, waist=94 + 19.3, anyPhysicalActivity=1, education=Education.COLLEGEGRADUATE, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.ONETOSIX, antiHypertensiveCount=1, statin=0, otherLipidLoweringMedicationCount=0, creatinine=0, initializeAfib=TestGCPModel.initializeAfib, ) self._test_case_two = Person( age=65 - 0.458555784 * 10, gender=NHANESGender.MALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_WHITE, sbp=120 + 0.3 * 10, dbp=80, # guessingon the centering standard for glucose...may have to check a1c=Person.convert_fasting_glucose_to_a1c(100 + 0.732746529 * 10), hdl=50, totChol=127 + 1.18 * 10, ldl=90, trig=150, bmi=26.6 + 0.419305619, waist=94 - 2.5, anyPhysicalActivity=1, education=Education.SOMEHIGHSCHOOL, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.ONETOSIX, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, creatinine=0, initializeAfib=TestGCPModel.initializeAfib, ) self._test_case_three = Person( age=65 - 0.358692676 * 10, gender=NHANESGender.FEMALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_BLACK, sbp=120 + 2.3 * 10, dbp=80, # guessingon the centering standard for glucose...may have to check a1c=Person.convert_fasting_glucose_to_a1c(100 + 0.8893 * 10), hdl=50, totChol=127 + 4.7769 * 10, ldl=90, trig=150, bmi=26.6 + 2.717159247, waist=94 + 9, anyPhysicalActivity=1, education=Education.LESSTHANHIGHSCHOOL, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.NONE, antiHypertensiveCount=1, statin=0, otherLipidLoweringMedicationCount=0, creatinine=0, initializeAfib=TestGCPModel.initializeAfib, ) self._test_case_one._randomEffects["gcp"] = 0 self._test_case_two._randomEffects["gcp"] = 0 self._test_case_three._randomEffects["gcp"] = 0
class TestPersonAdvanceOutcomes(unittest.TestCase): def setUp(self): self.joe = Person( 42, NHANESGender.MALE, NHANESRaceEthnicity.NON_HISPANIC_BLACK, 140, 90, 5.5, 50, 200, 25, 90, 150, 45, 0, Education.COLLEGEGRADUATE, SmokingStatus.NEVER, AlcoholCategory.NONE, 0, 0, 0, 0, initializeAFib, ) self.joe_with_mi = copy.deepcopy(self.joe) self.joe_with_mi.add_outcome_event(Outcome(OutcomeType.MI, False)) self.joe_with_stroke = copy.deepcopy(self.joe) self.joe_with_stroke.add_outcome_event(Outcome(OutcomeType.STROKE, False)) self._population_dataframe = init_vectorized_population_dataframe( [self.joe, self.joe_with_mi, self.joe_with_stroke], with_base_gcp=True, ) self._always_positive_repository = AlwaysPositiveOutcomeRepository() self._always_negative_repository = AlwaysNegativeOutcomeRepository() self.cvDeterminer = CVOutcomeDetermination(self._always_positive_repository) def test_dead_is_dead_advance_year(self): self.joe._alive[-1] = False with self.assertRaises(RuntimeError, msg="Person is dead. Can not advance year"): self.joe.advance_year(None, None) def test_dead_is_dead_advance_risk_factors(self): self.joe._alive[-1] = False with self.assertRaises(RuntimeError, msg="Person is dead. Can not advance risk factors"): self.joe.advance_risk_factors(None) def test_dead_is_dead_advance_outcomes(self): self.joe._alive[-1] = False with self.assertRaises(RuntimeError, msg="Person is dead. Can not advance outcomes"): self.joe.advance_outcomes(None) def test_will_have_fatal_mi(self): joe_data = self._population_dataframe.iloc[0] is_max_prob_mi_fatal = self.cvDeterminer._will_have_fatal_mi( joe_data, vectorized=True, overrideMIProb=1.0, ) is_min_prob_mi_fatal = self.cvDeterminer._will_have_fatal_mi( joe_data, vectorized=True, overrideMIProb=0.0, ) self.assertTrue(is_max_prob_mi_fatal) self.assertFalse(is_min_prob_mi_fatal) def test_fatal_mi_secondary_prob(self): self.cvDeterminer.mi_secondary_case_fatality = 1.0 self.cvDeterminer.mi_case_fatality = 0.0 joe_data = self._population_dataframe.iloc[0] joe_with_mi_data = self._population_dataframe.iloc[1] # same as joe_data plus 1 MI will_have_fatal_first_mi = self.cvDeterminer._will_have_fatal_mi( joe_data, vectorized=True, overrideMIProb=0.0, ) will_have_fatal_second_mi = self.cvDeterminer._will_have_fatal_mi( joe_with_mi_data, vectorized=True, overrideMIProb=0.0, ) self.assertFalse(will_have_fatal_first_mi) # even though the passed fatality rate is zero, it should be overriden by the # secondary rate given that joe had a prior MI self.assertTrue(will_have_fatal_second_mi) def test_fatal_stroke_secondary_prob(self): self.cvDeterminer.stroke_secondary_case_fatality = 1.0 self.cvDeterminer.stroke_case_fatality = 0.0 joe_data = self._population_dataframe.iloc[0] joe_with_stroke_data = self._population_dataframe.iloc[2] # same as joe_data plus 1 stroke will_have_fatal_first_stroke = self.cvDeterminer._will_have_fatal_stroke( joe_data, vectorized=True, overrideStrokeProb=0.0, ) will_have_fatal_second_stroke = self.cvDeterminer._will_have_fatal_stroke( joe_with_stroke_data, vectorized=True, overrideStrokeProb=0.0, ) self.assertFalse(will_have_fatal_first_stroke) # even though the passed fatality rate is zero, it shoudl be overriden by the # secondary rate given that joeclone had a prior stroke self.assertTrue(will_have_fatal_second_stroke) def test_will_have_fatal_stroke(self): joe_data = self._population_dataframe.iloc[0] is_max_prob_stroke_fatal = self.cvDeterminer._will_have_fatal_stroke( joe_data, vectorized=True, overrideStrokeProb=1.0, ) is_min_prob_stroke_fatal = self.cvDeterminer._will_have_fatal_stroke( joe_data, vectorized=True, overrideStrokeProb=0.0, ) self.assertTrue(is_max_prob_stroke_fatal) self.assertFalse(is_min_prob_stroke_fatal) def test_has_mi_vs_stroke(self): joe_data = self._population_dataframe.iloc[0] has_mi_max_manual_prob = self.cvDeterminer._will_have_mi( joe_data, outcome_model_repository=None, vectorized=False, manualMIProb=1.0, ) has_mi_min_manual_prob = self.cvDeterminer._will_have_mi( joe_data, outcome_model_repository=None, vectorized=False, manualMIProb=0.0, ) self.assertTrue(has_mi_max_manual_prob) self.assertFalse(has_mi_min_manual_prob) def test_advance_outcomes_fatal_mi(self): self._always_positive_repository.stroke_case_fatality = 1.0 self._always_positive_repository.mi_case_fatality = 1.0 self._always_positive_repository.manualStrokeMIProbability = 1.0 self.joe.advance_outcomes(self._always_positive_repository) self.assertTrue(self.joe.has_mi_during_simulation()) self.assertFalse(self.joe.has_stroke_during_simulation()) self.assertTrue(self.joe.is_dead()) def test_advance_outcomes_fatal_stroke(self): self._always_positive_repository.stroke_case_fatality = 1.0 self._always_positive_repository.mi_case_fatality = 1.0 self._always_positive_repository.manualStrokeMIProbability = 0.0 self.joe.advance_outcomes(self._always_positive_repository) self.assertFalse(self.joe.has_mi_during_simulation()) self.assertTrue(self.joe.has_stroke_during_simulation()) self.assertTrue(self.joe.is_dead()) def test_advance_outcomes_nonfatal_mi(self): self.assertEqual(0, self.joe.is_dead()) self._always_positive_repository.stroke_case_fatality = 0.0 self._always_positive_repository.mi_case_fatality = 0.0 self._always_positive_repository.manualStrokeMIProbability = 1.0 self.joe.advance_outcomes(self._always_positive_repository) self.assertTrue(self.joe.has_mi_during_simulation()) self.assertFalse(self.joe.has_stroke_during_simulation()) def test_advance_outcomes_nonfatal_stroke(self): self._always_positive_repository.stroke_case_fatality = 0.0 self._always_positive_repository.mi_case_fatality = 0.0 self._always_positive_repository.manualStrokeMIProbability = 0.0 self.joe.advance_outcomes(self._always_positive_repository) self.assertFalse(self.joe.has_mi_during_simulation()) self.assertTrue(self.joe.has_stroke_during_simulation())
class TestGCPModel(unittest.TestCase): def initializeAfib(person): return None def setUp(self): self._test_case_one = Person( age=65 - 0.828576318 * 10, gender=NHANESGender.FEMALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_WHITE, sbp=120 + 0.45 * 10, dbp=80, # guessingon the centering standard for glucose...may have to check a1c=Person.convert_fasting_glucose_to_a1c(100 - 1.1 * 10), hdl=50, totChol=127 - 3.64 * 10, ldl=90, trig=150, bmi=26.6 + 15.30517532, waist=94 + 19.3, anyPhysicalActivity=1, education=Education.COLLEGEGRADUATE, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.ONETOSIX, antiHypertensiveCount=1, statin=0, otherLipidLoweringMedicationCount=0, initializeAfib=TestGCPModel.initializeAfib) self._test_case_two = Person( age=65 - 0.458555784 * 10, gender=NHANESGender.MALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_WHITE, sbp=120 + 0.3 * 10, dbp=80, # guessingon the centering standard for glucose...may have to check a1c=Person.convert_fasting_glucose_to_a1c(100 + 0.732746529 * 10), hdl=50, totChol=127 + 1.18 * 10, ldl=90, trig=150, bmi=26.6 + 0.419305619, waist=94 - 2.5, anyPhysicalActivity=1, education=Education.SOMEHIGHSCHOOL, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.ONETOSIX, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, initializeAfib=TestGCPModel.initializeAfib) self._test_case_three = Person( age=65 - 0.358692676 * 10, gender=NHANESGender.FEMALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_BLACK, sbp=120 + 2.3 * 10, dbp=80, # guessingon the centering standard for glucose...may have to check a1c=Person.convert_fasting_glucose_to_a1c(100 + 0.8893 * 10), hdl=50, totChol=127 + 4.7769 * 10, ldl=90, trig=150, bmi=26.6 + 2.717159247, waist=94 + 9, anyPhysicalActivity=1, education=Education.LESSTHANHIGHSCHOOL, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.NONE, antiHypertensiveCount=1, statin=0, otherLipidLoweringMedicationCount=0, initializeAfib=TestGCPModel.initializeAfib) def test_baseline_gcp(self): # check that all of the random elements have been removed for testing... self.assertEqual( GCPModel().calc_linear_predictor(person=self._test_case_one, test=True), GCPModel().calc_linear_predictor(person=self._test_case_one, test=True)) # this is for the first person in teh spreadsheet (1569nomas)...comparator is GCP + backing out the cohort effect (NOMAS) self.assertAlmostEqual(64.45419405 - 2.7905, GCPModel().calc_linear_predictor( person=self._test_case_one, test=True), places=1) # this is for the 2nd person in the spreadhsheet (204180409594cardia)...comparabor is GCP margin + backing out the cohort effect (cardia) self.assertAlmostEqual(50.01645213 + 1.3320, GCPModel().calc_linear_predictor( person=self._test_case_two, test=True), places=1) # this is for the the first black person in the spreadsheet (J150483aric)...comparator is GCP + no cohort effect (ARIC) self.assertAlmostEqual(42.99471241, GCPModel().calc_linear_predictor( person=self._test_case_three, test=True), places=1) def test_gcp_after_one_year(self): # this is for the first person in teh spreadsheet (1569nomas)...comparator is GCP + backing out the cohort effect (NOMAS) self._test_case_one.advance_year( DoNotChangeRiskFactorsModelRepository(), AlwaysNegativeOutcomeRepository()) # account for the difference between the actual mean systolic change self.assertAlmostEqual(64.28862964 - 2.7905, GCPModel().calc_linear_predictor( person=self._test_case_one, test=True), places=1) def test_gcp_random_effect(self): self._test_case_one._randomEffects['gcp'] = 5 self.assertAlmostEqual(64.45419405 - 2.7905 + 5, GCPModel().get_risk_for_person( person=self._test_case_one, years=1, test=True), places=1)
class TestPersonWaveStatus(unittest.TestCase): def setUp(self): self.oldJoe = Person( age=60, gender=NHANESGender.MALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_BLACK, sbp=140, dbp=90, a1c=5.5, hdl=50, totChol=200, bmi=25, ldl=90, trig=150, waist=45, anyPhysicalActivity=0, education=Education.COLLEGEGRADUATE, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.NONE, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, initializeAfib=initializeAFib) self.youngJoe = Person( age=40, gender=NHANESGender.MALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_BLACK, sbp=140, dbp=90, a1c=5.5, hdl=50, totChol=200, bmi=25, ldl=90, trig=150, waist=45, anyPhysicalActivity=0, education=Education.COLLEGEGRADUATE, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.NONE, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, initializeAfib=initializeAFib) def testStatusAfterFatalStroke(self): self.youngJoe.advance_year(TestRiskModelRepository(), AgeOver50CausesFatalStroke()) self.assertEqual(41, self.youngJoe._age[-1]) self.assertEqual(False, self.youngJoe.is_dead()) self.assertEqual(False, self.youngJoe._stroke) self.assertEqual(True, self.youngJoe.alive_at_start_of_wave(1)) self.assertEqual(True, self.youngJoe.alive_at_start_of_wave(2)) with self.assertRaises(Exception): self.youngJoe.alive_at_start_of_wave(3) self.youngJoe.advance_year(TestRiskModelRepository(), AgeOver50CausesFatalStroke()) self.assertEqual(True, self.youngJoe.alive_at_start_of_wave(3)) self.oldJoe.advance_year(TestRiskModelRepository(), AgeOver50CausesFatalStroke()) self.assertEqual(60, self.oldJoe._age[-1]) self.assertEqual(True, self.oldJoe.is_dead()) self.assertEqual(True, self.oldJoe._stroke) self.assertEqual(True, self.oldJoe.alive_at_start_of_wave(1)) self.assertEqual(False, self.oldJoe.alive_at_start_of_wave(2)) # this is called to verify that it DOES NOT throw an excepiotn self.oldJoe.alive_at_start_of_wave(3) def testNonCVMortalityLeadsToCorrectStatus(self): self.youngJoe.advance_year(TestRiskModelRepository(), AgeOver50CausesNonCVMortality()) self.assertEqual(41, self.youngJoe._age[-1]) self.assertEqual(False, self.youngJoe.is_dead()) self.assertEqual(False, self.youngJoe._stroke) self.assertEqual(True, self.youngJoe.alive_at_start_of_wave(1)) self.assertEqual(True, self.youngJoe.alive_at_start_of_wave(2)) with self.assertRaises(Exception): self.youngJoe.alive_at_start_of_wave(3) self.youngJoe.advance_year(TestRiskModelRepository(), AgeOver50CausesNonCVMortality()) self.assertEqual(True, self.youngJoe.alive_at_start_of_wave(3)) self.oldJoe.advance_year(TestRiskModelRepository(), AgeOver50CausesNonCVMortality()) self.assertEqual(60, self.oldJoe._age[-1]) self.assertEqual(True, self.oldJoe.is_dead()) self.assertEqual(False, self.oldJoe._stroke) self.assertEqual(True, self.oldJoe.alive_at_start_of_wave(1)) self.assertEqual(False, self.oldJoe.alive_at_start_of_wave(2)) # this is called to verify that it DOES NOT throw an excepiotn self.oldJoe.alive_at_start_of_wave(3) def testHasFatalStrokeInWaveIsCaptured(self): self.oldJoe.advance_year(TestRiskModelRepository(), AgeOver50CausesFatalStroke()) self.assertEqual(True, self.oldJoe.has_stroke_during_simulation()) self.assertEqual(True, self.oldJoe.has_stroke_during_wave(1)) with self.assertRaises(Exception): self.oldJoe.has_stroke_during_wave(0) # calling to make sure it does NOT raise an exception...you should # be able to ask whether somebody has a stroke in a wave after they are dead, the answer is # "No" self.assertEqual(False, self.oldJoe.has_stroke_during_wave(2)) def testNonFatalStrokeInWaveWithNonCVDeathIsCaptured(self): self.oldJoe.advance_year(TestRiskModelRepository(), NonFatalStrokeAndNonCVMortality()) self.assertEqual(True, self.oldJoe.has_stroke_during_simulation()) self.assertEqual(True, self.oldJoe.has_stroke_during_wave(1)) self.assertEqual(True, self.oldJoe.is_dead())
class TestPersonAdvanceOutcomes(unittest.TestCase): def setUp(self): self.joe = Person(42, NHANESGender.MALE, NHANESRaceEthnicity.NON_HISPANIC_BLACK, 140, 90, 5.5, 50, 200, 25, 90, 150, 45, 0, Education.COLLEGEGRADUATE, SmokingStatus.NEVER, AlcoholCategory.NONE, 0, 0, 0, initializeAFib) self._always_positive_repository = AlwaysPositiveOutcomeRepository() self._always_negative_repository = AlwaysNegativeOutcomeRepository() self.cvDeterminer = CVOutcomeDetermination( self._always_positive_repository) def test_dead_is_dead_advance_year(self): self.joe._alive[-1] = False with self.assertRaises(RuntimeError, msg="Person is dead. Can not advance year"): self.joe.advance_year(None, None) def test_dead_is_dead_advance_risk_factors(self): self.joe._alive[-1] = False with self.assertRaises( RuntimeError, msg="Person is dead. Can not advance risk factors"): self.joe.advance_risk_factors(None) def test_dead_is_dead_advance_outcomes(self): self.joe._alive[-1] = False with self.assertRaises(RuntimeError, msg="Person is dead. Can not advance outcomes"): self.joe.advance_outcomes(None) def test_will_have_fatal_mi(self): self.assertEqual(self.cvDeterminer._will_have_fatal_mi(self.joe, 1.0), 1) self.assertEqual(self.cvDeterminer._will_have_fatal_mi(self.joe, 0.0), 0) def test_fatal_mi_secondary_prob(self): self.cvDeterminer.mi_secondary_case_fatality = 1.0 self.cvDeterminer.mi_case_fatality = 0.0 joeClone = copy.deepcopy(self.joe) self.assertEqual(self.cvDeterminer._will_have_fatal_mi(joeClone, 0.0), 0) joeClone._outcomes[OutcomeType.MI] = (joeClone._age, Outcome(OutcomeType.MI, False)) # even though the passed fatality rate is zero, it shoudl be overriden by the # secondary rate given that joeclone had a prior MI self.assertEqual(self.cvDeterminer._will_have_fatal_mi(joeClone, 0.0), 1) def test_fatal_stroke_secondary_prob(self): self.cvDeterminer.stroke_secondary_case_fatality = 1.0 self.cvDeterminer.stroke_case_fatality = 0.0 joeClone = copy.deepcopy(self.joe) self.assertEqual( self.cvDeterminer._will_have_fatal_stroke(joeClone, 0.0), 0) joeClone._outcomes[OutcomeType.STROKE] = (joeClone._age, Outcome( OutcomeType.STROKE, False)) # even though the passed fatality rate is zero, it shoudl be overriden by the # secondary rate given that joeclone had a prior stroke self.assertEqual( self.cvDeterminer._will_have_fatal_stroke(joeClone, 0.0), 1) def test_will_have_fatal_stroke(self): self.assertEqual( self.cvDeterminer._will_have_fatal_stroke(self.joe, 1.0), 1) self.assertEqual( self.cvDeterminer._will_have_fatal_stroke(self.joe, 0.0), 0) def test_has_mi_vs_stroke(self): self.assertEqual(self.cvDeterminer._will_have_mi(self.joe, None, 1.0), 1) self.assertEqual(self.cvDeterminer._will_have_mi(self.joe, None, 0.0), 0) def test_advance_outcomes_fatal_mi(self): self._always_positive_repository.stroke_case_fatality = 1.0 self._always_positive_repository.mi_case_fatality = 1.0 self._always_positive_repository.manualStrokeMIProbability = 1.0 self.joe.advance_outcomes(self._always_positive_repository) self.assertTrue(self.joe.has_mi_during_simulation()) self.assertFalse(self.joe.has_stroke_during_simulation()) self.assertTrue(self.joe.is_dead()) def test_advance_outcomes_fatal_stroke(self): self._always_positive_repository.stroke_case_fatality = 1.0 self._always_positive_repository.mi_case_fatality = 1.0 self._always_positive_repository.manualStrokeMIProbability = 0.0 self.joe.advance_outcomes(self._always_positive_repository) self.assertFalse(self.joe.has_mi_during_simulation()) self.assertTrue(self.joe.has_stroke_during_simulation()) self.assertTrue(self.joe.is_dead()) def test_advance_outcomes_nonfatal_mi(self): self.assertEqual(0, self.joe.is_dead()) self._always_positive_repository.stroke_case_fatality = 0.0 self._always_positive_repository.mi_case_fatality = 0.0 self._always_positive_repository.manualStrokeMIProbability = 1.0 self.joe.advance_outcomes(self._always_positive_repository) self.assertTrue(self.joe.has_mi_during_simulation()) self.assertFalse(self.joe.has_stroke_during_simulation()) def test_advance_outcomes_nonfatal_stroke(self): self._always_positive_repository.stroke_case_fatality = 0.0 self._always_positive_repository.mi_case_fatality = 0.0 self._always_positive_repository.manualStrokeMIProbability = 0.0 self.joe.advance_outcomes(self._always_positive_repository) self.assertFalse(self.joe.has_mi_during_simulation()) self.assertTrue(self.joe.has_stroke_during_simulation())
def setUp(self): # 2740200061fos self._test_case_one = Person( age=54.060233, gender=NHANESGender.FEMALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_WHITE, sbp=120, dbp=80, # guessingon the centering standard for glucose...may have to check a1c=Person.convert_fasting_glucose_to_a1c(100), hdl=50, totChol=150, ldl=90, trig=150, bmi=26.6, waist=94, anyPhysicalActivity=1, education=Education.HIGHSCHOOLGRADUATE, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.ONETOSIX, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, creatinine=0, initializeAfib=TestDementiaModel.initializeAfib, initializationRepository=InitializationRepository(), ) self._test_case_one._gcp[0] = 58.68 self._test_case_one._gcp.append(self._test_case_one._gcp[0] - 1.1078128) # 2740201178fos self._test_case_two = Person( age=34.504449, gender=NHANESGender.MALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_WHITE, sbp=120, dbp=80, # guessingon the centering standard for glucose...may have to check a1c=Person.convert_fasting_glucose_to_a1c(100), hdl=50, totChol=150, ldl=90, trig=150, bmi=26.6, waist=94, anyPhysicalActivity=1, education=Education.SOMECOLLEGE, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.ONETOSIX, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, creatinine=0, initializeAfib=TestDementiaModel.initializeAfib, initializationRepository=InitializationRepository(), ) self._test_case_two._gcp[0] = 58.68 self._test_case_two._gcp.append(self._test_case_two._gcp[0] - 1.7339989) self._test_case_one_parameteric = Person( age=40, gender=NHANESGender.MALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_BLACK, sbp=120, dbp=80, # guessingon the centering standard for glucose...may have to check a1c=Person.convert_fasting_glucose_to_a1c(100), hdl=50, totChol=150, ldl=90, trig=150, bmi=26.6, waist=94, anyPhysicalActivity=1, education=Education.LESSTHANHIGHSCHOOL, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.ONETOSIX, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, creatinine=0, initializeAfib=TestDementiaModel.initializeAfib, initializationRepository=InitializationRepository(), ) self._test_case_one_parameteric._gcp[0] = 25 # GCP slope is zero self._test_case_one_parameteric._gcp.append( self._test_case_one._gcp[0]) # test case 71 in rep_gdta. self._test_case_two_parametric = Person( age=80, gender=NHANESGender.FEMALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_BLACK, sbp=120, dbp=80, # guessingon the centering standard for glucose...may have to check a1c=Person.convert_fasting_glucose_to_a1c(100), hdl=50, totChol=150, ldl=90, trig=150, bmi=26.6, waist=94, anyPhysicalActivity=1, education=Education.COLLEGEGRADUATE, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.ONETOSIX, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, creatinine=0, initializeAfib=TestDementiaModel.initializeAfib, initializationRepository=InitializationRepository(), ) self._test_case_two_parametric._gcp[0] = 75 self._test_case_two_parametric._gcp.append(self._test_case_two._gcp[0]) # test case 72 in rep_gdta. self._test_case_three_parametric = Person( age=80, gender=NHANESGender.FEMALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_WHITE, sbp=120, dbp=80, # guessingon the centering standard for glucose...may have to check a1c=Person.convert_fasting_glucose_to_a1c(100), hdl=50, totChol=150, ldl=90, trig=150, bmi=26.6, waist=94, anyPhysicalActivity=1, education=Education.COLLEGEGRADUATE, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.ONETOSIX, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, creatinine=0, initializeAfib=TestDementiaModel.initializeAfib, initializationRepository=InitializationRepository(), ) self._test_case_three_parametric._gcp[0] = 75 self._test_case_three_parametric._gcp.append( self._test_case_two._gcp[0]) self._population_dataframe = init_vectorized_population_dataframe([ self._test_case_one, self._test_case_two, ])
class TestResetPersonAndRollBackEvents(unittest.TestCase): def setUp(self): self.baseAge = 55 self.baseSBP = 120 self._white_male = Person( age=self.baseAge, gender=NHANESGender.MALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_WHITE, sbp=self.baseSBP, dbp=80, a1c=6, hdl=50, totChol=213, ldl=90, trig=150, bmi=22, waist=34, anyPhysicalActivity=0, education=Education.COLLEGEGRADUATE, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.NONE, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, initializeAfib=initializeAfib) self._white_male_copy_paste = Person( age=self.baseAge, gender=NHANESGender.MALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_WHITE, sbp=self.baseSBP, dbp=80, a1c=6, hdl=50, totChol=213, ldl=90, trig=150, bmi=22, waist=34, anyPhysicalActivity=0, education=Education.COLLEGEGRADUATE, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.NONE, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, initializeAfib=initializeAfib) self._white_male_plus_one_year = Person( age=self.baseAge + 1, gender=NHANESGender.MALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_WHITE, sbp=self.baseSBP, dbp=80, a1c=6, hdl=50, totChol=213, ldl=90, trig=150, bmi=22, waist=34, anyPhysicalActivity=0, education=Education.COLLEGEGRADUATE, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.NONE, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, initializeAfib=initializeAfib) self._white_female = Person( age=self.baseAge, gender=NHANESGender.FEMALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_WHITE, sbp=self.baseSBP, dbp=80, a1c=6, hdl=50, totChol=213, ldl=90, trig=150, bmi=22, waist=34, anyPhysicalActivity=0, education=Education.COLLEGEGRADUATE, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.NONE, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, initializeAfib=initializeAfib) self._black_female = Person( age=self.baseAge, gender=NHANESGender.FEMALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_BLACK, sbp=self.baseSBP, dbp=80, a1c=6, hdl=50, totChol=213, ldl=90, trig=150, bmi=22, waist=34, anyPhysicalActivity=0, education=Education.COLLEGEGRADUATE, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.NONE, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, initializeAfib=initializeAfib) self._white_male_plus_sbp = Person( age=self.baseAge + 1, gender=NHANESGender.MALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_WHITE, sbp=self.baseSBP + 10, dbp=80, a1c=6, hdl=50, totChol=213, ldl=90, trig=150, bmi=22, waist=34, anyPhysicalActivity=0, education=Education.COLLEGEGRADUATE, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.NONE, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, initializeAfib=initializeAfib) self._white_male_plus_dbp = Person( age=self.baseAge + 1, gender=NHANESGender.MALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_WHITE, sbp=self.baseSBP, dbp=90, a1c=6, hdl=50, totChol=213, ldl=90, trig=150, bmi=22, waist=34, anyPhysicalActivity=0, education=Education.COLLEGEGRADUATE, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.NONE, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, initializeAfib=initializeAfib) self._white_male_plus_a1c = Person( age=self.baseAge + 1, gender=NHANESGender.MALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_WHITE, sbp=self.baseSBP, dbp=80, a1c=7, hdl=50, totChol=213, ldl=90, trig=150, bmi=22, waist=34, anyPhysicalActivity=0, education=Education.COLLEGEGRADUATE, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.NONE, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, initializeAfib=initializeAfib) self._white_male_plus_hdl = Person( age=self.baseAge + 1, gender=NHANESGender.MALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_WHITE, sbp=self.baseSBP, dbp=80, a1c=6, hdl=60, totChol=213, ldl=90, trig=150, bmi=22, waist=34, anyPhysicalActivity=0, education=Education.COLLEGEGRADUATE, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.NONE, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, initializeAfib=initializeAfib) self._white_male_plus_totChol = Person( age=self.baseAge + 1, gender=NHANESGender.MALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_WHITE, sbp=self.baseSBP, dbp=80, a1c=6, hdl=50, totChol=223, ldl=90, trig=150, bmi=22, waist=34, anyPhysicalActivity=0, education=Education.COLLEGEGRADUATE, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.NONE, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, initializeAfib=initializeAfib) self._white_male_plus_ldl = Person( age=self.baseAge + 1, gender=NHANESGender.MALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_WHITE, sbp=self.baseSBP, dbp=80, a1c=6, hdl=50, totChol=213, ldl=100, trig=150, bmi=22, waist=34, anyPhysicalActivity=0, education=Education.COLLEGEGRADUATE, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.NONE, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, initializeAfib=initializeAfib) self._white_male_plus_trig = Person( age=self.baseAge + 1, gender=NHANESGender.MALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_WHITE, sbp=self.baseSBP, dbp=80, a1c=6, hdl=50, totChol=213, ldl=90, trig=160, bmi=22, waist=34, anyPhysicalActivity=0, education=Education.COLLEGEGRADUATE, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.NONE, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, initializeAfib=initializeAfib) self._white_male_plus_bmi = Person( age=self.baseAge + 1, gender=NHANESGender.MALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_WHITE, sbp=self.baseSBP, dbp=80, a1c=6, hdl=50, totChol=213, ldl=90, trig=150, bmi=25, waist=34, anyPhysicalActivity=0, education=Education.COLLEGEGRADUATE, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.NONE, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, initializeAfib=initializeAfib) self._white_male_plus_waist = Person( age=self.baseAge + 1, gender=NHANESGender.MALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_WHITE, sbp=self.baseSBP, dbp=80, a1c=6, hdl=50, totChol=213, ldl=90, trig=150, bmi=22, waist=36, anyPhysicalActivity=0, education=Education.COLLEGEGRADUATE, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.NONE, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, initializeAfib=initializeAfib) self._white_male_plus_activity = Person( age=self.baseAge + 1, gender=NHANESGender.MALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_WHITE, sbp=self.baseSBP, dbp=80, a1c=6, hdl=50, totChol=213, ldl=90, trig=150, bmi=22, waist=34, anyPhysicalActivity=1, education=Education.COLLEGEGRADUATE, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.NONE, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, initializeAfib=initializeAfib) self._white_male_minus_edudcation = Person( age=self.baseAge + 1, gender=NHANESGender.MALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_WHITE, sbp=self.baseSBP, dbp=80, a1c=6, hdl=50, totChol=213, ldl=90, trig=150, bmi=22, waist=34, anyPhysicalActivity=1, education=Education.HIGHSCHOOLGRADUATE, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.NONE, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, initializeAfib=initializeAfib) self._white_male_plus_smoking = Person( age=self.baseAge + 1, gender=NHANESGender.MALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_WHITE, sbp=self.baseSBP, dbp=80, a1c=6, hdl=50, totChol=213, ldl=90, trig=150, bmi=22, waist=34, anyPhysicalActivity=1, education=Education.COLLEGEGRADUATE, smokingStatus=SmokingStatus.CURRENT, alcohol=AlcoholCategory.NONE, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, initializeAfib=initializeAfib) self._white_male_plus_bpMed = Person( age=self.baseAge + 1, gender=NHANESGender.MALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_WHITE, sbp=self.baseSBP, dbp=80, a1c=6, hdl=50, totChol=213, ldl=90, trig=150, bmi=22, waist=34, anyPhysicalActivity=0, education=Education.COLLEGEGRADUATE, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.NONE, antiHypertensiveCount=1, statin=0, otherLipidLoweringMedicationCount=0, initializeAfib=initializeAfib) self._white_male_plus_statin = Person( age=self.baseAge + 1, gender=NHANESGender.MALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_WHITE, sbp=self.baseSBP, dbp=80, a1c=6, hdl=50, totChol=213, ldl=90, trig=150, bmi=22, waist=34, anyPhysicalActivity=0, education=Education.COLLEGEGRADUATE, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.NONE, antiHypertensiveCount=0, statin=1, otherLipidLoweringMedicationCount=0, initializeAfib=initializeAfib) self._white_male_plus_lipid = Person( age=self.baseAge + 1, gender=NHANESGender.MALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_WHITE, sbp=self.baseSBP, dbp=80, a1c=6, hdl=50, totChol=213, ldl=90, trig=150, bmi=22, waist=34, anyPhysicalActivity=0, education=Education.COLLEGEGRADUATE, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.NONE, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=1, initializeAfib=initializeAfib) self._white_male_plus_afib = Person( age=self.baseAge + 1, gender=NHANESGender.MALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_WHITE, sbp=self.baseSBP, dbp=80, a1c=6, hdl=50, totChol=213, ldl=90, trig=150, bmi=22, waist=34, anyPhysicalActivity=0, education=Education.COLLEGEGRADUATE, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.NONE, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, initializeAfib=initializeAfibAlwaysPositive) self._baseline_stroke_person = Person( age=self.baseAge, gender=NHANESGender.MALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_WHITE, sbp=self.baseSBP, dbp=80, a1c=6, hdl=50, totChol=213, ldl=90, trig=150, bmi=22, waist=34, anyPhysicalActivity=0, education=Education.COLLEGEGRADUATE, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.NONE, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, initializeAfib=initializeAfib, selfReportStrokeAge=50) self._baseline_stroke_person_copy_paste = Person( age=self.baseAge, gender=NHANESGender.MALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_WHITE, sbp=self.baseSBP, dbp=80, a1c=6, hdl=50, totChol=213, ldl=90, trig=150, bmi=22, waist=34, anyPhysicalActivity=0, education=Education.COLLEGEGRADUATE, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.NONE, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, initializeAfib=initializeAfib, selfReportStrokeAge=50) def testResetBasicAttributes(self): self._white_male.advance_year(TestRiskModelRepository(), AlwaysNonFatalStrokeOutcomeRepository()) self._baseline_stroke_person.advance_year( TestRiskModelRepository(), AlwaysFatalStrokeOutcomeRepository()) self.assertEqual(2, len(self._white_male._dbp)) self._white_male.reset_to_baseline() self.assertEqual(1, len(self._white_male._dbp)) self.assertEqual(1, len(self._white_male._totChol)) self.assertEqual(1, len(self._white_male._trig)) self.assertEqual(1, len(self._white_male._trig)) self.assertEqual(1, len(self._white_male._sbp)) self.assertEqual(self.baseSBP, self._white_male._sbp[-1]) self.assertEqual(self.baseAge, self._white_male._age[-1]) def testResetOutcomes(self): self._white_male.advance_year(TestRiskModelRepository(), AlwaysNonFatalStrokeOutcomeRepository()) self._baseline_stroke_person.advance_year( TestRiskModelRepository(), AlwaysFatalStrokeOutcomeRepository()) self.assertEqual(1, len(self._white_male._outcomes[OutcomeType.STROKE])) self._white_male.reset_to_baseline() self.assertEqual(0, len(self._white_male._outcomes[OutcomeType.STROKE])) def testResetOutcomesPreservesPreSimOutcomes(self): self._white_male.advance_year(TestRiskModelRepository(), AlwaysNonFatalStrokeOutcomeRepository()) self._baseline_stroke_person.advance_year( TestRiskModelRepository(), AlwaysFatalStrokeOutcomeRepository()) self.assertEqual( 2, len(self._baseline_stroke_person._outcomes[OutcomeType.STROKE])) self._baseline_stroke_person.reset_to_baseline() self.assertEqual( 1, len(self._baseline_stroke_person._outcomes[OutcomeType.STROKE])) def testRollbackNonFatalEvent(self): self._white_male.advance_year(TestRiskModelRepository(), AlwaysNonFatalStrokeOutcomeRepository()) self._baseline_stroke_person.advance_year( TestRiskModelRepository(), AlwaysFatalStrokeOutcomeRepository()) self.assertEqual(False, self._white_male.has_stroke_prior_to_simulation()) self.assertEqual(True, self._white_male.has_stroke_during_simulation()) self.assertEqual(True, self._white_male.has_stroke_during_wave(1)) self._white_male.rollback_most_recent_event(OutcomeType.STROKE) self.assertEqual(False, self._white_male.has_stroke_prior_to_simulation()) self.assertEqual(False, self._white_male.has_stroke_during_wave(1)) self.assertEqual(False, self._white_male.has_stroke_during_simulation()) def testRollbackFatalEvent(self): self._white_male.advance_year(TestRiskModelRepository(), AlwaysNonFatalStrokeOutcomeRepository()) self._baseline_stroke_person.advance_year( TestRiskModelRepository(), AlwaysFatalStrokeOutcomeRepository()) self.assertEqual( True, self._baseline_stroke_person.has_stroke_during_simulation()) self.assertEqual( True, self._baseline_stroke_person.has_stroke_prior_to_simulation()) self.assertEqual( True, self._baseline_stroke_person.has_stroke_during_wave(1)) self.assertEqual(True, self._baseline_stroke_person.is_dead()) self._baseline_stroke_person.rollback_most_recent_event( OutcomeType.STROKE) self.assertEqual( True, self._baseline_stroke_person.has_stroke_prior_to_simulation()) self.assertEqual( False, self._baseline_stroke_person.has_stroke_during_wave(1)) self.assertEqual( False, self._baseline_stroke_person.has_stroke_during_simulation()) self.assertEqual(False, self._baseline_stroke_person.is_dead()) self.assertEqual(self.baseAge + 1, self._baseline_stroke_person._age[-1]) def testBasePatientEquals(self): self.assertTrue(self._white_male == self._white_male_copy_paste) self.assertEqual(self._white_male, self._white_male_copy_paste) self.assertNotEqual(self._white_male, self._white_female) self.assertNotEqual(self._white_female, self._black_female) self.assertNotEqual(self._white_male, self._white_male_minus_edudcation) self.assertNotEqual(self._white_male, self._white_male_plus_a1c) self.assertNotEqual(self._white_male, self._white_male_plus_activity) self.assertNotEqual(self._white_male, self._white_male_plus_afib) self.assertNotEqual(self._white_male, self._white_male_plus_bmi) self.assertNotEqual(self._white_male, self._white_male_plus_dbp) self.assertNotEqual(self._white_male, self._white_male_plus_hdl) self.assertNotEqual(self._white_male, self._white_male_plus_ldl) self.assertNotEqual(self._white_male, self._white_male_plus_lipid) self.assertNotEqual(self._white_male, self._white_male_plus_one_year) self.assertNotEqual(self._white_male, self._white_male_plus_sbp) self.assertNotEqual(self._white_male, self._white_male_plus_smoking) self.assertNotEqual(self._white_male, self._white_male_plus_statin) self.assertNotEqual(self._white_male, self._white_male_plus_totChol) self.assertNotEqual(self._white_male, self._white_male_plus_trig) self.assertNotEqual(self._white_male, self._white_male_plus_waist) def testBaselineEqualityAfterAdvancingAYear(self): self._white_male.advance_year(TestRiskModelRepository(), NothingHappensRepository()) self._white_male_copy_paste.advance_year(TestRiskModelRepository(), NothingHappensRepository()) self.assertEqual(self._white_male, self._white_male_copy_paste) def testBasePatientWithBaselineStroke(self): self.assertNotEqual(self._white_male, self._baseline_stroke_person) self.assertEqual(self._baseline_stroke_person, self._baseline_stroke_person_copy_paste) self._baseline_stroke_person.advance_year(TestRiskModelRepository(), NothingHappensRepository()) self._baseline_stroke_person_copy_paste.advance_year( TestRiskModelRepository(), NothingHappensRepository()) self.assertEqual(self._baseline_stroke_person, self._baseline_stroke_person_copy_paste) def testBasePatientWithCVEvents(self): self.assertEqual(self._white_male_copy_paste, self._white_male) self._white_male.advance_year(TestRiskModelRepository(), AlwaysNonFatalStrokeOutcomeRepository()) self.assertNotEqual(self._white_male, self._white_male_copy_paste) self._white_male_copy_paste.advance_year( TestRiskModelRepository(), AlwaysNonFatalStrokeOutcomeRepository()) self.assertEqual(self._white_male_copy_paste, self._white_male) def testBasePatientWithNonCVDeath(self): self.assertEqual(self._white_male_copy_paste, self._white_male) self._white_male.advance_year(TestRiskModelRepository(), AlwaysNonCVDeathRepository()) self.assertNotEqual(self._white_male, self._white_male_copy_paste) self._white_male_copy_paste.advance_year(TestRiskModelRepository(), NothingHappensRepository()) self.assertNotEqual(self._white_male_copy_paste, self._white_male) def testBasePatientWithNonCVDeathOtherWay(self): self.assertEqual(self._white_male_copy_paste, self._white_male) self._white_male.advance_year(TestRiskModelRepository(), AlwaysNonCVDeathRepository()) self.assertNotEqual(self._white_male, self._white_male_copy_paste) self._white_male_copy_paste.advance_year(TestRiskModelRepository(), AlwaysNonCVDeathRepository()) self.assertEqual(self._white_male_copy_paste, self._white_male) def testDeepCopy(self): self.assertEqual(self._white_male, copy.deepcopy(self._white_male)) self._white_male.advance_year(TestRiskModelRepository(), NothingHappensRepository()) self.assertEqual(self._white_male, copy.deepcopy(self._white_male)) self._white_male.advance_year(TestRiskModelRepository(), AlwaysNonFatalStrokeOutcomeRepository()) self.assertEqual(self._white_male, copy.deepcopy(self._white_male)) self._white_male.advance_year(TestRiskModelRepository(), AlwaysNonCVDeathRepository()) self.assertEqual(self._white_male, copy.deepcopy(self._white_male))
def setUp(self): self._white_male = Person( age=55, gender=NHANESGender.MALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_WHITE, sbp=120, dbp=80, a1c=6, hdl=50, totChol=213, ldl=90, trig=150, bmi=22, waist=34, anyPhysicalActivity=0, education=Education.COLLEGEGRADUATE, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.NONE, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, initializeAfib=initializeAfib) self._black_male = Person( age=55, gender=NHANESGender.MALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_BLACK, sbp=120, dbp=80, a1c=6, hdl=50, totChol=200, ldl=90, trig=150, bmi=22, waist=34, anyPhysicalActivity=0, education=Education.COLLEGEGRADUATE, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.NONE, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, initializeAfib=initializeAfib) self._black_treated_male = Person( age=55, gender=NHANESGender.MALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_BLACK, sbp=120, dbp=80, a1c=6, hdl=50, totChol=200, ldl=90, trig=150, bmi=22, waist=34, anyPhysicalActivity=0, education=Education.COLLEGEGRADUATE, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.NONE, antiHypertensiveCount=1, statin=0, otherLipidLoweringMedicationCount=0, initializeAfib=initializeAfib) self._white_female = Person( age=55, gender=NHANESGender.FEMALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_WHITE, sbp=120, dbp=80, a1c=6, hdl=50, totChol=213, ldl=90, trig=150, bmi=22, waist=34, anyPhysicalActivity=0, education=Education.COLLEGEGRADUATE, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.NONE, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, initializeAfib=initializeAfib) self._black_female = Person( age=55, gender=NHANESGender.FEMALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_BLACK, sbp=120, dbp=80, a1c=6, hdl=50, totChol=213, ldl=90, trig=150, bmi=22, waist=34, anyPhysicalActivity=0, education=Education.COLLEGEGRADUATE, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.NONE, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, initializeAfib=initializeAfib) self._outcome_model_repository = OutcomeModelRepository()
def setUp(self): self.baseAge = 55 self.baseSBP = 120 self._white_male = Person( age=self.baseAge, gender=NHANESGender.MALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_WHITE, sbp=self.baseSBP, dbp=80, a1c=6, hdl=50, totChol=213, ldl=90, trig=150, bmi=22, waist=34, anyPhysicalActivity=0, education=Education.COLLEGEGRADUATE, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.NONE, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, initializeAfib=initializeAfib) self._white_male_copy_paste = Person( age=self.baseAge, gender=NHANESGender.MALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_WHITE, sbp=self.baseSBP, dbp=80, a1c=6, hdl=50, totChol=213, ldl=90, trig=150, bmi=22, waist=34, anyPhysicalActivity=0, education=Education.COLLEGEGRADUATE, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.NONE, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, initializeAfib=initializeAfib) self._white_male_plus_one_year = Person( age=self.baseAge + 1, gender=NHANESGender.MALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_WHITE, sbp=self.baseSBP, dbp=80, a1c=6, hdl=50, totChol=213, ldl=90, trig=150, bmi=22, waist=34, anyPhysicalActivity=0, education=Education.COLLEGEGRADUATE, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.NONE, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, initializeAfib=initializeAfib) self._white_female = Person( age=self.baseAge, gender=NHANESGender.FEMALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_WHITE, sbp=self.baseSBP, dbp=80, a1c=6, hdl=50, totChol=213, ldl=90, trig=150, bmi=22, waist=34, anyPhysicalActivity=0, education=Education.COLLEGEGRADUATE, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.NONE, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, initializeAfib=initializeAfib) self._black_female = Person( age=self.baseAge, gender=NHANESGender.FEMALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_BLACK, sbp=self.baseSBP, dbp=80, a1c=6, hdl=50, totChol=213, ldl=90, trig=150, bmi=22, waist=34, anyPhysicalActivity=0, education=Education.COLLEGEGRADUATE, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.NONE, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, initializeAfib=initializeAfib) self._white_male_plus_sbp = Person( age=self.baseAge + 1, gender=NHANESGender.MALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_WHITE, sbp=self.baseSBP + 10, dbp=80, a1c=6, hdl=50, totChol=213, ldl=90, trig=150, bmi=22, waist=34, anyPhysicalActivity=0, education=Education.COLLEGEGRADUATE, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.NONE, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, initializeAfib=initializeAfib) self._white_male_plus_dbp = Person( age=self.baseAge + 1, gender=NHANESGender.MALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_WHITE, sbp=self.baseSBP, dbp=90, a1c=6, hdl=50, totChol=213, ldl=90, trig=150, bmi=22, waist=34, anyPhysicalActivity=0, education=Education.COLLEGEGRADUATE, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.NONE, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, initializeAfib=initializeAfib) self._white_male_plus_a1c = Person( age=self.baseAge + 1, gender=NHANESGender.MALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_WHITE, sbp=self.baseSBP, dbp=80, a1c=7, hdl=50, totChol=213, ldl=90, trig=150, bmi=22, waist=34, anyPhysicalActivity=0, education=Education.COLLEGEGRADUATE, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.NONE, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, initializeAfib=initializeAfib) self._white_male_plus_hdl = Person( age=self.baseAge + 1, gender=NHANESGender.MALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_WHITE, sbp=self.baseSBP, dbp=80, a1c=6, hdl=60, totChol=213, ldl=90, trig=150, bmi=22, waist=34, anyPhysicalActivity=0, education=Education.COLLEGEGRADUATE, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.NONE, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, initializeAfib=initializeAfib) self._white_male_plus_totChol = Person( age=self.baseAge + 1, gender=NHANESGender.MALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_WHITE, sbp=self.baseSBP, dbp=80, a1c=6, hdl=50, totChol=223, ldl=90, trig=150, bmi=22, waist=34, anyPhysicalActivity=0, education=Education.COLLEGEGRADUATE, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.NONE, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, initializeAfib=initializeAfib) self._white_male_plus_ldl = Person( age=self.baseAge + 1, gender=NHANESGender.MALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_WHITE, sbp=self.baseSBP, dbp=80, a1c=6, hdl=50, totChol=213, ldl=100, trig=150, bmi=22, waist=34, anyPhysicalActivity=0, education=Education.COLLEGEGRADUATE, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.NONE, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, initializeAfib=initializeAfib) self._white_male_plus_trig = Person( age=self.baseAge + 1, gender=NHANESGender.MALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_WHITE, sbp=self.baseSBP, dbp=80, a1c=6, hdl=50, totChol=213, ldl=90, trig=160, bmi=22, waist=34, anyPhysicalActivity=0, education=Education.COLLEGEGRADUATE, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.NONE, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, initializeAfib=initializeAfib) self._white_male_plus_bmi = Person( age=self.baseAge + 1, gender=NHANESGender.MALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_WHITE, sbp=self.baseSBP, dbp=80, a1c=6, hdl=50, totChol=213, ldl=90, trig=150, bmi=25, waist=34, anyPhysicalActivity=0, education=Education.COLLEGEGRADUATE, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.NONE, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, initializeAfib=initializeAfib) self._white_male_plus_waist = Person( age=self.baseAge + 1, gender=NHANESGender.MALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_WHITE, sbp=self.baseSBP, dbp=80, a1c=6, hdl=50, totChol=213, ldl=90, trig=150, bmi=22, waist=36, anyPhysicalActivity=0, education=Education.COLLEGEGRADUATE, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.NONE, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, initializeAfib=initializeAfib) self._white_male_plus_activity = Person( age=self.baseAge + 1, gender=NHANESGender.MALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_WHITE, sbp=self.baseSBP, dbp=80, a1c=6, hdl=50, totChol=213, ldl=90, trig=150, bmi=22, waist=34, anyPhysicalActivity=1, education=Education.COLLEGEGRADUATE, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.NONE, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, initializeAfib=initializeAfib) self._white_male_minus_edudcation = Person( age=self.baseAge + 1, gender=NHANESGender.MALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_WHITE, sbp=self.baseSBP, dbp=80, a1c=6, hdl=50, totChol=213, ldl=90, trig=150, bmi=22, waist=34, anyPhysicalActivity=1, education=Education.HIGHSCHOOLGRADUATE, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.NONE, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, initializeAfib=initializeAfib) self._white_male_plus_smoking = Person( age=self.baseAge + 1, gender=NHANESGender.MALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_WHITE, sbp=self.baseSBP, dbp=80, a1c=6, hdl=50, totChol=213, ldl=90, trig=150, bmi=22, waist=34, anyPhysicalActivity=1, education=Education.COLLEGEGRADUATE, smokingStatus=SmokingStatus.CURRENT, alcohol=AlcoholCategory.NONE, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, initializeAfib=initializeAfib) self._white_male_plus_bpMed = Person( age=self.baseAge + 1, gender=NHANESGender.MALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_WHITE, sbp=self.baseSBP, dbp=80, a1c=6, hdl=50, totChol=213, ldl=90, trig=150, bmi=22, waist=34, anyPhysicalActivity=0, education=Education.COLLEGEGRADUATE, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.NONE, antiHypertensiveCount=1, statin=0, otherLipidLoweringMedicationCount=0, initializeAfib=initializeAfib) self._white_male_plus_statin = Person( age=self.baseAge + 1, gender=NHANESGender.MALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_WHITE, sbp=self.baseSBP, dbp=80, a1c=6, hdl=50, totChol=213, ldl=90, trig=150, bmi=22, waist=34, anyPhysicalActivity=0, education=Education.COLLEGEGRADUATE, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.NONE, antiHypertensiveCount=0, statin=1, otherLipidLoweringMedicationCount=0, initializeAfib=initializeAfib) self._white_male_plus_lipid = Person( age=self.baseAge + 1, gender=NHANESGender.MALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_WHITE, sbp=self.baseSBP, dbp=80, a1c=6, hdl=50, totChol=213, ldl=90, trig=150, bmi=22, waist=34, anyPhysicalActivity=0, education=Education.COLLEGEGRADUATE, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.NONE, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=1, initializeAfib=initializeAfib) self._white_male_plus_afib = Person( age=self.baseAge + 1, gender=NHANESGender.MALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_WHITE, sbp=self.baseSBP, dbp=80, a1c=6, hdl=50, totChol=213, ldl=90, trig=150, bmi=22, waist=34, anyPhysicalActivity=0, education=Education.COLLEGEGRADUATE, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.NONE, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, initializeAfib=initializeAfibAlwaysPositive) self._baseline_stroke_person = Person( age=self.baseAge, gender=NHANESGender.MALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_WHITE, sbp=self.baseSBP, dbp=80, a1c=6, hdl=50, totChol=213, ldl=90, trig=150, bmi=22, waist=34, anyPhysicalActivity=0, education=Education.COLLEGEGRADUATE, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.NONE, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, initializeAfib=initializeAfib, selfReportStrokeAge=50) self._baseline_stroke_person_copy_paste = Person( age=self.baseAge, gender=NHANESGender.MALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_WHITE, sbp=self.baseSBP, dbp=80, a1c=6, hdl=50, totChol=213, ldl=90, trig=150, bmi=22, waist=34, anyPhysicalActivity=0, education=Education.COLLEGEGRADUATE, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.NONE, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, initializeAfib=initializeAfib, selfReportStrokeAge=50)
class TestTreatmentStrategy(unittest.TestCase): def initializeAfib(person): return None def setUp(self): self.baselineSBP = 140 self.baselineDBP = 80 self._test_person = Person( age=75, gender=0, raceEthnicity=1, sbp=self.baselineSBP, dbp=self.baselineDBP, a1c=6.5, hdl=50, totChol=210, ldl=90, trig=150, bmi=22, waist=50, anyPhysicalActivity=0, education=Education.COLLEGEGRADUATE, smokingStatus=1, alcohol=0, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, initializeAfib=TestTreatmentStrategy.initializeAfib) self._risk_model_repository = TestRiskModelRepository() # setup so that the SBP always stays the same self._risk_model_repository._repository['sbp']._params['age'] = 0 self._risk_model_repository._repository['sbp']._params['sbp'] = 1.0 self._risk_model_repository._repository['sbp']._params['intercept'] = 0 self._risk_model_repository._repository['dbp']._params['age'] = 0 self._risk_model_repository._repository['dbp']._params['dbp'] = 1.0 self._risk_model_repository._repository['dbp']._params['sbp'] = 0 self._risk_model_repository._repository['dbp']._params['intercept'] = 0 # setup so that the anti-hypertensive count stays at zero self._risk_model_repository._repository[ 'antiHypertensiveCount']._params['age'] = 0 self._risk_model_repository._repository[ 'antiHypertensiveCount']._params['sbp'] = 0 self._risk_model_repository._repository[ 'antiHypertensiveCount']._params['intercept'] = 0 def add_a_single_blood_pressure_medication_strategy(person): return {'_antiHypertensiveCount': 1}, {'_sbp': -5, '_dbp': -3}, {} def testSimpleBPTreatmentStrategy(self): self._test_person.advance_treatment(self._risk_model_repository) self._test_person.advance_risk_factors(self._risk_model_repository) self.assertEqual(self.baselineSBP, self._test_person._sbp[1]) self.assertEqual(self.baselineDBP, self._test_person._dbp[1]) self.assertEqual(0, self._test_person._antiHypertensiveCount[1]) self._test_person._bpTreatmentStrategy = TestTreatmentStrategy.add_a_single_blood_pressure_medication_strategy self._test_person.advance_treatment(self._risk_model_repository) self._test_person.advance_risk_factors(self._risk_model_repository) self.assertEqual(self.baselineSBP - 5, self._test_person._sbp[2]) self.assertEqual(self.baselineDBP - 3, self._test_person._dbp[2]) self.assertEqual(1, self._test_person._antiHypertensiveCount[2])
def setUp(self): popSize = 100 age = np.random.normal(loc=70, scale=20, size=popSize) sbp = age * 1.05 + np.random.normal(loc=40, scale=30, size=popSize) df = pd.DataFrame({"age": age, "sbp": sbp}) simpleModel = statsmodel.ols(formula="sbp ~ age", data=df) self.simpleModelResultSM = simpleModel.fit() self.simpleModelResult = RegressionModel( self.simpleModelResultSM.params.to_dict(), self.simpleModelResultSM.bse.to_dict(), self.simpleModelResultSM.resid.mean(), self.simpleModelResultSM.resid.std(), ) self.person = Person( age=80, gender=NHANESGender.MALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_WHITE, sbp=120, dbp=80, a1c=5.5, hdl=50, totChol=200, bmi=27, ldl=90, trig=150, waist=70, anyPhysicalActivity=0, education=Education.COLLEGEGRADUATE, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.NONE, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, creatinine=0.0, initializeAfib=initializeAfib, ) self.people = [ Person( age=80, gender=NHANESGender.MALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_WHITE, sbp=bpinstance, dbp=80, a1c=5.5, hdl=50, totChol=200, bmi=27, ldl=90, trig=150, waist=70, anyPhysicalActivity=0, education=Education.COLLEGEGRADUATE, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.NONE, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, creatinine=0.0, initializeAfib=initializeAfib, ) for bpinstance in sbp ] for person in self.people: self.advancePerson(person) self.population_dataframe = init_vectorized_population_dataframe( self.people, with_base_gcp=True, ) df2 = pd.DataFrame({ "age": age, "sbp": [person._sbp[-1] for person in self.people], "meanSbp": [np.array(person._sbp).mean() for person in self.people], }) self.meanModelResultSM = statsmodel.ols(formula="sbp ~ age + meanSbp", data=df2).fit() self.meanModelResult = RegressionModel( self.meanModelResultSM.params.to_dict(), self.meanModelResultSM.bse.to_dict(), self.meanModelResultSM.resid.mean(), self.meanModelResultSM.resid.std(), ) df3 = pd.DataFrame({ "age": age, "sbp": [person._sbp[-1] for person in self.people], "logMeanSbp": [np.log(np.array(person._sbp).mean()) for person in self.people], }) self.logMeanModelResultSM = statsmodel.ols( formula="sbp ~ age + logMeanSbp", data=df3).fit() self.logMeanModelResult = RegressionModel( self.logMeanModelResultSM.params.to_dict(), self.logMeanModelResultSM.bse.to_dict(), self.logMeanModelResultSM.resid.mean(), self.logMeanModelResultSM.resid.std(), ) race = np.random.randint(1, 5, size=popSize) df4 = pd.DataFrame({"age": age, "sbp": sbp, "raceEthnicity": race}) df4.raceEthnicity = df4.raceEthnicity.astype("category") self.raceModelResultSM = statsmodel.ols( formula="sbp ~ age + raceEthnicity", data=df4).fit() self.raceModelResult = RegressionModel( self.raceModelResultSM.params.to_dict(), self.raceModelResultSM.bse.to_dict(), self.raceModelResultSM.resid.mean(), self.raceModelResultSM.resid.std(), ) dfMeanAndLag = pd.DataFrame({ "age": age, "sbp": [person._sbp[-1] for person in self.people], "meanSbp": [np.array(person._sbp).mean() for person in self.people], "lagSbp": [person._sbp[-1] for person in self.people], }) self.meanLagModelResultSM = statsmodel.ols( formula="sbp ~ age + meanSbp + lagSbp", data=dfMeanAndLag).fit() self.meanLagModelResult = RegressionModel( self.meanLagModelResultSM.params.to_dict(), self.meanLagModelResultSM.bse.to_dict(), self.meanLagModelResultSM.resid.mean(), self.meanLagModelResultSM.resid.std(), ) self.ageSbpInteractionCoeff = 0.02 self.sbpInteractionCoeff = 0.5 self.interactionModel = RegressionModel( { "meanSbp#age": self.ageSbpInteractionCoeff, "meanSbp": self.sbpInteractionCoeff, "Intercept": 0, }, { "meanSbp#age": 0.0, "meanSbp": 0.0 }, 0, 0, )
def setUp(self): self._black_female_high_cr = Person( age=52, gender=NHANESGender.FEMALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_BLACK, sbp=120, dbp=80, a1c=Person.convert_fasting_glucose_to_a1c(100), hdl=50, totChol=150, ldl=90, trig=150, bmi=26.6, waist=94, anyPhysicalActivity=1, education=Education.HIGHSCHOOLGRADUATE, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.ONETOSIX, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, creatinine=0.8, initializeAfib=TestCKDEquation.initializeAfib, ) self._black_female_low_cr = Person( age=52, gender=NHANESGender.FEMALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_BLACK, sbp=120, dbp=80, a1c=Person.convert_fasting_glucose_to_a1c(100), hdl=50, totChol=150, ldl=90, trig=150, bmi=26.6, waist=94, anyPhysicalActivity=1, education=Education.HIGHSCHOOLGRADUATE, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.ONETOSIX, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, creatinine=0.4, initializeAfib=TestCKDEquation.initializeAfib, ) self._white_male_high_cr = Person( age=52, gender=NHANESGender.MALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_WHITE, sbp=120, dbp=80, a1c=Person.convert_fasting_glucose_to_a1c(100), hdl=50, totChol=150, ldl=90, trig=150, bmi=26.6, waist=94, anyPhysicalActivity=1, education=Education.HIGHSCHOOLGRADUATE, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.ONETOSIX, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, creatinine=1.2, initializeAfib=TestCKDEquation.initializeAfib, ) self._white_male_low_cr = Person( age=52, gender=NHANESGender.MALE, raceEthnicity=NHANESRaceEthnicity.NON_HISPANIC_WHITE, sbp=120, dbp=80, a1c=Person.convert_fasting_glucose_to_a1c(100), hdl=50, totChol=150, ldl=90, trig=150, bmi=26.6, waist=94, anyPhysicalActivity=1, education=Education.HIGHSCHOOLGRADUATE, smokingStatus=SmokingStatus.NEVER, alcohol=AlcoholCategory.ONETOSIX, antiHypertensiveCount=0, statin=0, otherLipidLoweringMedicationCount=0, creatinine=0.1, initializeAfib=TestCKDEquation.initializeAfib, )