def test_baseline_gcp(self): # check that all of the random elements have been removed for testing... self.assertEqual( GCPModel().get_risk_for_person(person=self._test_case_one, test=True), GCPModel().get_risk_for_person(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().get_risk_for_person(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().get_risk_for_person(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().get_risk_for_person(person=self._test_case_three, test=True), places=1, )
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 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, )
def init_vectorized_population_dataframe(person_list: List[Person], *, with_base_gcp=False): if with_base_gcp: gcp_model = GCPModel() for p in person_list: if len(p._gcp) == 0: base_gcp = gcp_model.get_risk_for_person(p) p._gcp.append(base_gcp) people = pd.Series(person_list) population = Population(people) return population.get_people_current_state_and_summary_as_dataframe()
def test_dont_advance_dead_people_in_population(self): # add GCP to advance successfully joe_base_gcp = GCPModel().get_risk_for_person(self.joe) self.joe._gcp.append(joe_base_gcp) # use ClonePopulation: sets up repositories, populationIndex, and 2+ people to workaround self.dummy_population = ClonePopulation(self.joe, 2) initial_joe = self.dummy_population._people.iloc[0] initial_joe._alive.append(False) expected_risk_factor_length = len(initial_joe._sbp) # this should NOT raise an error if it is (correctly) not trying to # advance on poor dead, joe self.dummy_population.advance_vectorized(1) advanced_joe = self.dummy_population._people.iloc[0] self.assertEqual(expected_risk_factor_length, len(advanced_joe._sbp))
def test_gcp_random_effect_independent_per_person(self): expected_case_one_gcp = 66.66369405 expected_case_two_gcp = 51.34845213 self._test_case_one._randomEffects["gcp"] = 5 gcp_model = GCPModel() actual_case_one_gcp = gcp_model.get_risk_for_person( self._test_case_one, test=True) actual_case_two_gcp = gcp_model.get_risk_for_person( self._test_case_two, test=True) self.assertAlmostEqual(expected_case_one_gcp, actual_case_one_gcp, places=1) self.assertAlmostEqual(expected_case_two_gcp, actual_case_two_gcp, places=1)
def __init__(self): super(OutcomeModelRepository, self).__init__() self._models = {} self._models[OutcomeModelType.GLOBAL_COGNITIVE_PERFORMANCE] = GCPModel()
def get_gcp_vectorized(self, person): return GCPModel().get_risk_for_person(person, vectorized=True, test=True)
def get_gcp(self, person): return GCPModel().get_risk_for_person(person, test=True)
def __init__(self): self.mi_case_fatality = CVOutcomeDetermination.default_mi_case_fatality self.secondary_mi_case_fatality = CVOutcomeDetermination.default_secondary_mi_case_fatality self.stroke_case_fatality = CVOutcomeDetermination.default_stroke_case_fatality self.secondary_stroke_case_fatality = ( CVOutcomeDetermination.default_secondary_stroke_case_fatality) self.secondary_prevention_multiplier = ( CVOutcomeDetermination.default_secondary_prevention_multiplier) self.outcomeDet = CVOutcomeDetermination( self.mi_case_fatality, self.stroke_case_fatality, self.secondary_mi_case_fatality, self.secondary_stroke_case_fatality, self.secondary_prevention_multiplier, ) # variable used in testing to control whether a patient will have a stroke or mi self.manualStrokeMIProbability = None self._models = {} femaleCVCoefficients = { "lagAge": 0.106501, "black": 0.432440, "lagSbp#lagSbp": 0.000056, "lagSbp": 0.017666, "current_bp_treatment": 0.731678, "current_diabetes": 0.943970, "current_smoker": 1.009790, "lagAge#black": -0.008580, "lagSbp#current_bp_treatment": -0.003647, "lagSbp#black": 0.006208, "black#current_bp_treatment": 0.152968, "lagAge#lagSbp": -0.000153, "black#current_diabetes": 0.115232, "black#current_smoker": -0.092231, "lagSbp#black#current_bp_treatment": -0.000173, "lagAge#lagSbp#black": -0.000094, "Intercept": -12.823110, } maleCVCoefficients = { "lagAge": 0.064200, "black": 0.482835, "lagSbp#lagSbp": -0.000061, "lagSbp": 0.038950, "current_bp_treatment": 2.055533, "current_diabetes": 0.842209, "current_smoker": 0.895589, "lagAge#black": 0, "lagSbp#current_bp_treatment": -0.014207, "lagSbp#black": 0.011609, "black#current_bp_treatment": -0.119460, "lagAge#lagSbp": 0.000025, "black#current_diabetes": -0.077214, "black#current_smoker": -0.226771, "lagSbp#black#current_bp_treatment": 0.004190, "lagAge#lagSbp#black": -0.000199, "Intercept": -11.679980, } self._models[OutcomeModelType.CARDIOVASCULAR] = { "female": ASCVDOutcomeModel( RegressionModel( coefficients=femaleCVCoefficients, coefficient_standard_errors={ key: 0 for key in femaleCVCoefficients }, residual_mean=0, residual_standard_deviation=0, ), tot_chol_hdl_ratio=0.151318, black_race_x_tot_chol_hdl_ratio=0.070498, ), "male": ASCVDOutcomeModel( RegressionModel( coefficients=maleCVCoefficients, coefficient_standard_errors={ key: 0 for key in maleCVCoefficients }, residual_mean=0, residual_standard_deviation=0, ), tot_chol_hdl_ratio=0.193307, black_race_x_tot_chol_hdl_ratio=-0.117749, ), } self._models[ OutcomeModelType.GLOBAL_COGNITIVE_PERFORMANCE] = GCPModel() self._models[OutcomeModelType.DEMENTIA] = DementiaModel() # This represents non-cardiovascular mortality.. nonCVModelSpec = load_model_spec("nhanesMortalityModelLogit") mortModel = StatsModelLogisticRiskFactorModel( RegressionModel(**nonCVModelSpec), False) # Recalibrate mortalitly model to align with life table data, as explored in notebook # buildNHANESMortalityModel mortModel.non_intercept_params[ "age"] = mortModel.non_intercept_params["age"] * -1 mortModel.non_intercept_params["squareAge"] = ( mortModel.non_intercept_params["squareAge"] * 4) self._models[OutcomeModelType.NON_CV_MORTALITY] = mortModel
def get_initializers(self): return { "_gcp": GCPModel().get_risk_for_person, "_qalys": QALYAssignmentStrategy().get_next_qaly, }
def __init__(self): self.mi_case_fatality = CVOutcomeDetermination.default_mi_case_fatality self.secondary_mi_case_fatality = CVOutcomeDetermination.default_secondary_mi_case_fatality self.stroke_case_fatality = CVOutcomeDetermination.default_stroke_case_fatality self.secondary_stroke_case_fatality = CVOutcomeDetermination.default_secondary_stroke_case_fatality self.secondary_prevention_multiplier = CVOutcomeDetermination.default_secondary_prevention_multiplier # variable used in testing to control whether a patient will have a stroke or mi self.manualStrokeMIProbability = None self._models = {} femaleCVCoefficients = { 'lagAge': 0.106501, 'black': 0.432440, 'lagSbp#lagSbp': 0.000056, 'lagSbp': 0.017666, 'current_bp_treatment': 0.731678, 'current_diabetes': 0.943970, 'current_smoker': 1.009790, 'lagAge#black': -0.008580, 'lagSbp#current_bp_treatment': -0.003647, 'lagSbp#black': 0.006208, 'black#current_bp_treatment': 0.152968, 'lagAge#lagSbp': -0.000153, 'black#current_diabetes': 0.115232, 'black#current_smoker': -0.092231, 'lagSbp#black#current_bp_treatment': -0.000173, 'lagAge#lagSbp#black': -0.000094, 'Intercept': -12.823110 } maleCVCoefficients = { 'lagAge': 0.064200, 'black': 0.482835, 'lagSbp#lagSbp': -0.000061, 'lagSbp': 0.038950, 'current_bp_treatment': 2.055533, 'current_diabetes': 0.842209, 'current_smoker': 0.895589, 'lagAge#black': 0, 'lagSbp#current_bp_treatment': -0.014207, 'lagSbp#black': 0.011609, 'black#current_bp_treatment': -0.119460, 'lagAge#lagSbp': 0.000025, 'black#current_diabetes': -0.077214, 'black#current_smoker': -0.226771, 'lagSbp#black#current_bp_treatment': 0.004190, 'lagAge#lagSbp#black': -0.000199, 'Intercept': -11.679980 } self._models[OutcomeModelType.CARDIOVASCULAR] = { "female": ASCVDOutcomeModel(RegressionModel( coefficients=femaleCVCoefficients, coefficient_standard_errors={ key: 0 for key in femaleCVCoefficients }, residual_mean=0, residual_standard_deviation=0), tot_chol_hdl_ratio=0.151318, black_race_x_tot_chol_hdl_ratio=0.070498), "male": ASCVDOutcomeModel(RegressionModel(coefficients=maleCVCoefficients, coefficient_standard_errors={ key: 0 for key in maleCVCoefficients }, residual_mean=0, residual_standard_deviation=0), tot_chol_hdl_ratio=0.193307, black_race_x_tot_chol_hdl_ratio=-0.117749) } self._models[ OutcomeModelType.GLOBAL_COGNITIVE_PERFORMANCE] = GCPModel() # This represents non-cardiovascular mortality.. self._models[ OutcomeModelType.NON_CV_MORTALITY] = self.initialize_cox_model( "nhanesMortalityModel")