def recode(age, female, ethnicity, smoking, sbp, cvdHist, bpld, statin, anticoag, hba1c, tchol, hdl, creat, acr, target="CHF"): coefInfo = CHD_INFO if target == "MI": coefInfo = MI_INFO if target == "STROKE": coefInfo = STROKE_INFO """ Calculate the survival value """ xFeat = np.array([ clean_age(age), female, ethnicity, smoking, clean_bp(sbp), cvdHist, bpld, statin, anticoag, clean_hba1c(hba1c), clean_tot_chol(tchol), clean_hdl(hdl), creat, clean_acr(acr) ]) return cox_surv(xFeat, coefInfo["coef"], coefInfo["s0"], coefInfo["const"])
def fremantle(age, male, cvd, hba1c, acr, hdl_mmol, seurope, aboriginal): """ Calculate the risk for cardiovascular disease using the coefficients from the Fremantle Cohort Parameters ---------- age : numeric Age of subject isMale : boolean or int Subject is male (True or False) cvd: boolean or int Previous history of CVD (True or False) hba1c : numeric Hba1c (%) of subject acr : numeric Urinary albumin : creatinine ratio in mg/mmol hdl : numeric High density lipid cholestrol in mmol/L seurope : bool or int Subject is Southern European (True or False) aboriginal : bool or int Subject is Indigenous Australian (True or False) """ xFeat = np.array([ clean_age(age), male, cvd, np.log(clean_hba1c(hba1c)), np.log(clean_acr(acr)), np.log(clean_hdl(hdl_mmol, meas="mmol")), seurope, aboriginal ]) return cox_surv(xFeat, FREMANTLE_COEF, FREMANTLE_SM, FREMANTLE_CONST)
def frs_simple(female, age, bmi, sbp, htn, smk, diab): """ 10-year risk calculated using the Simple Non-Laboratory Framingham Risk Score (FRS) Calculation. Parameters ---------- female : boolean age : numeric Age of subject bmi : numeric BMI of subject sbp : numeric Systolic blood pressure of subject ht_treat : bool or int Treatment for hypertension (True or False) smk : bool or int Subject is smoker (True or False) diab : bool or int Subject has diabetes (True or False) """ xFeat = np.array([np.log(clean_age(age)), np.log(clean_bmi(bmi)), np.log(clean_bp(sbp))*(1-htn), np.log(clean_bp(sbp))*htn, smk, diab]) genderInfo = NONLAB_MEN if female: genderInfo = NONLAB_WOMEN return cox_surv(xFeat, genderInfo["coef"], genderInfo["s0"], genderInfo["const"])
def hkdr_chd(age, female, cur_smoker, diab_dur, egfr, acr, nonhdl_mmol): """ Calculate the risk for coronary heart disease using the coefficients from the HKDR CHD Cohort Parameters ---------- age : numeric Age of subject isFemale : boolean or int Subject is female (True or False) curSmoke: boolean or int Previous history of CVD (True or False) diabDur : numeric Nubmer of years of diabetes egfr : numeric Estimated Glomerular Filteration Rate acr : numeric Urinary albumin : creatinine ratio in mg/mmol nonHDL : numeric Non-HDL cholesterol (mmol/L) """ xFeat = np.array([ clean_age(age), female, cur_smoker, clean_diab_dur(diab_dur), np.log10(clean_egfr(egfr)), np.log10(1 + clean_acr(acr)), clean_nonhdl(nonhdl_mmol, meas="mmol") ]) return cox_surv(xFeat, HKDR_CHD["coef"], HKDR_CHD["sm"], HKDR_CHD["const"], HKDR_CHD["shrink"])
def dmcx(age, egfr, tchdl, acr, smoker, diab_dur, female, sbp, dbp, hba1c, htn_med, bmi, insulin, aGlucose): """ Calculate the risk for cardiovascular disease using the coefficients from the DMCX Cohort Parameters ---------- age : numeric Age of subject """ # do some preprocessing age = clean_age(age) egfr = clean_egfr(egfr) sbp = clean_bp(sbp) dbp = clean_bp(dbp) bmi = clean_bmi(bmi) hba1c = clean_hba1c(hba1c) tchdl = clean_tchdl(tchdl) xFeat = np.array([ age, egfr >= 60 and egfr < 90, egfr >= 30 and egfr < 60, egfr < 30, tchdl, np.log(clean_acr(acr) + 1), smoker, clean_diab_dur(diab_dur), sbp, hba1c, htn_med, dbp, bmi, insulin, dbp**2, bmi**2, sbp**2, hba1c**2, age * tchdl, age * hba1c, age * smoker, aGlucose ]) coefInfo = MALE_DCMX if female: coefInfo = FEMALE_DCMX return cox_surv(xFeat, coefInfo["coef"], coefInfo["sm"], coefInfo["const"])
def hkdr_hf(female, age, bmi, hba1c, acr, hb, chdHist): """ Calculate the risk for heart failure using the coefficients from the HKDR Cohort Parameters ---------- age : numeric Age of subject bmi : numeric BMI of the subject (in kg/m^2) hba1c: numeric HBA1C (%) acr : numeric Urinary albumin : creatinine ratio in mg/mmol hb : numeric Blood Hemoglobin (g/dl) chdHist : boolean or int Subject had CHD (true or False) """ baseSurv = HKDR_HF["male_sm"] if female: baseSurv = HKDR_HF["female_sm"] xFeat = np.array([ clean_age(age), clean_bmi(bmi), clean_hba1c(hba1c), np.log10(1 + clean_acr(acr)), clean_hb(hb), chdHist ]) return cox_surv(xFeat, HKDR_HF["coef"], baseSurv, HKDR_HF["const"], HKDR_HF["shrink"])
def hkdr_stroke(age, hba1c, acr, chd): xFeat = np.array( [clean_age(age), clean_hba1c(hba1c), np.log10(clean_acr(acr)), chd]) return cox_surv(xFeat, HKDR_STROKE["coef"], HKDR_STROKE["sm"], HKDR_STROKE["const"])
def pce(female, ac, age, tot_chol, hdl, sbp, smoker, htn, diab, risk=5): if risk not in [5, 10]: raise NotImplementedError("Does not support risk that is not 5 or 10") baseSurv = "s10" if risk == 5: baseSurv = "s5" # figure out what the betas are cohortInfo = WHITE_MALE if female and ac: cohortInfo = BLACK_FEMALE elif female: cohortInfo = WHITE_FEMALE elif ac: cohortInfo = BLACK_MALE age = clean_age(age) tot_chol = clean_tot_chol(tot_chol) hdl = clean_hdl(hdl) sbp = clean_bp(sbp) xFeat = np.array([ np.log(age), np.log(age)**2, np.log(tot_chol), np.log(tot_chol) * np.log(age), np.log(hdl), np.log(hdl) * np.log(age), np.log(sbp) * (1 - htn), np.log(age) * np.log(sbp) * (1 - htn), np.log(sbp) * htn, np.log(age) * np.log(sbp) * htn, smoker, smoker * np.log(age), diab ]) s = cox_surv(xFeat, cohortInfo["coef"], cohortInfo[baseSurv], cohortInfo["const"]) return s
def dial(is_male, age, bmi, cur_smoke, sbp, non_hdl, hba1c, egfr, microalbumin, macroalbumin, diab_dur, cvd_hist, insulin, hz_treat=0, high_risk_county=False): # fix the age to be within 34-94 age = np.clip(clean_age(age), 34, 94) diab_dur = int(round(clean_diab_dur(diab_dur))) bmi = clean_bmi(bmi) sbp = clean_bp(sbp) non_hdl = clean_nonhdl(non_hdl, meas="mmol") egfr = clean_egfr(egfr) hba1c = clean_hba1c(hba1c, meas="mmol") xFeat = np.array([ is_male, age * is_male, bmi - 30, bmi**2 - 30**2, cur_smoke, age * cur_smoke, sbp - 140, sbp**2 - 140**2, non_hdl - 3.8, non_hdl**2 - 3.8**2, hba1c - 50, hba1c**2 - 50**2, egfr - 80, egfr**2 - 80**2, microalbumin, macroalbumin, diab_dur, cvd_hist, age * cvd_hist, insulin, age * insulin, hz_treat, high_risk_county ]) # look-up the age-specific value s0 = AGE_S0[age] return cox_surv(xFeat, DIAL_COEF, s0)
def qdiabetes(age, male, bmi, diab_dur, ac, easian, hba1c, tchdl, sbp, heavy_smoke, moderate_smoke, light_smoke, prev_smoke, afib, cvd, renal, tYear=5, dmt1=False): genderInfo = FEMALE_CCF fractalFunc = _frac_poly_female if male: genderInfo = MALE_CCF fractalFunc = _frac_poly_male return _survival(clean_age(age), clean_bmi(bmi), clean_diab_dur(diab_dur, 0), ac, easian, clean_hba1c(hba1c, meas="mmol"), clean_tchdl(tchdl), clean_bp(sbp), heavy_smoke, moderate_smoke, light_smoke, prev_smoke, afib, cvd, renal, dmt1, genderInfo, tYear, fractalFunc)
def ukpds(ageDiab, age, female, ac, smoking, hba1c, sbp, tchdl, tYear=10): """ Calculate the number of years to forecast the risk. """ xFeat = np.array([clean_age(age)-55, female, ac, bool(smoking), clean_hba1c(hba1c)-6.72, (clean_bp(sbp) - 135.7)/10, np.log(clean_tchdl(tchdl))-1.59]) q = Q_0 * np.prod(np.power(BETA, xFeat)) uscore = 1 - np.exp(-q * D**(age-ageDiab)* (1-D**tYear)/ (1 - D)) return max(uscore, 0.0)
def frs_primary(female, age, tot_chol, hdl, sbp, htn, smk, diab): """ """ xFeat = np.array([np.log(clean_age(age)), np.log(clean_tot_chol(tot_chol)), np.log(clean_hdl(hdl)), np.log(clean_bp(sbp))*(1-htn), np.log(clean_bp(sbp))*htn, smk, diab]) genderInfo = LAB_MEN if female: genderInfo = LAB_WOMEN return cox_surv(xFeat, genderInfo["coef"], genderInfo["s0"], genderInfo["const"])
def aric(age, male, cauc, tc, hdl, sbp, htn, smoke): # set the coeff based on male or female genderInfo = FEMALE_INFO if male: genderInfo = MALE_INFO age = clean_age(age) tc = clean_tot_chol(tc) hdl = clean_hdl(hdl) xFeat = np.array([ age, age**2, cauc, tc >= 200 and tc <= 279, tc >= 280, hdl < 45, hdl >= 45 and hdl <= 49, clean_bp(sbp), htn, smoke ]) return cox_surv(xFeat, genderInfo["coef"], genderInfo["sm"], genderInfo["xBetaMed"])