예제 #1
0
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"])
예제 #2
0
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"])
예제 #3
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"])
예제 #4
0
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"])
예제 #5
0
def ndr(diab_age,
        diab_dur,
        tchdl,
        hba1c,
        sbp,
        bmi,
        male,
        smoker,
        microalbum,
        macroalbum,
        afib,
        cvd,
        risk=5):
    if risk not in [4, 5]:
        raise NotImplementedError("Does not support risk that is not 4 or 5")
    baseSurv = S0_4
    if risk == 5:
        baseSurv = S0_5
    xFeat = np.array([
        diab_age - 53.858,
        clean_diab_dur(diab_dur) - 7.7360,
        np.log(clean_tchdl(tchdl)) - 1.3948,
        np.log(clean_hba1c(hba1c)) - 1.9736,
        np.log(clean_bp(sbp)) - 4.9441,
        np.log(clean_bmi(bmi)) - 3.3718, male - 0.6005, smoker - 0.1778,
        microalbum - 0.1604, macroalbum - 0.0638, afib - 0.0319, cvd - 0.1525
    ])
    s = cox_surv(xFeat, BETA, baseSurv)
    return s
예제 #6
0
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)
예제 #7
0
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
예제 #8
0
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)
예제 #9
0
def ukpdsom2_mi_female(ac,
                       diab_dur,
                       diab_age,
                       egfr,
                       hba1c,
                       ldl,
                       mmalb,
                       pvd,
                       sbp,
                       cur_smoke,
                       wbc,
                       chf_hist,
                       chd_hist,
                       tYear=1):
    """
    Calculate the number of years to forecast the risk.
    """
    ldl = clean_ldl(ldl)
    egfr = clean_egfr(egfr)
    xFeat = np.array([
        ac, diab_age, egfr / 10 if egfr < 60 else 0,
        clean_hba1c(hba1c), ldl * 10 if ldl > 35 else 0, mmalb >= 50, pvd,
        clean_bp(sbp) / 10, cur_smoke, wbc, chf_hist, chd_hist
    ])
    return weibull_surv(xFeat, MI_FEMALE_PARAMS["beta"],
                        MI_FEMALE_PARAMS["lambda"], diab_dur, diab_dur + tYear,
                        MI_MALE_PARAMS["rho"])
예제 #10
0
def ukpdsom2_mi_male(ac,
                     diab_dur,
                     diab_age,
                     easian,
                     hba1c,
                     hdl,
                     ldl,
                     mmalb,
                     pvd,
                     sbp,
                     cur_smoke,
                     wbc,
                     amp_hist,
                     chf_hist,
                     chd_hist,
                     stroke_hist,
                     tYear=1):
    """
    Calculate the number of years to forecast the risk.
    """

    xFeat = np.array([
        ac, diab_age, easian,
        clean_hba1c(hba1c),
        clean_hdl(hdl) * 10,
        clean_ldl(ldl) * 10, mmalb >= 50, pvd,
        clean_bp(sbp) / 10, cur_smoke, wbc, amp_hist, chf_hist, chd_hist,
        stroke_hist
    ])
    return weibull_surv(xFeat, MI_MALE_PARAMS["beta"],
                        MI_MALE_PARAMS["lambda"], diab_dur, diab_dur + tYear,
                        MI_MALE_PARAMS["rho"])
예제 #11
0
def score(female, age, chol_mmol, sbp, smoking, low_risk):
    sc = None
    beta = HIGH_RISK_MEN
    if female and low_risk:
        beta = LOW_RISK_WOMEN
    elif female:
        beta = HIGH_RISK_WOMEN
    elif low_risk:
        beta = LOW_RISK_MEN
    sc = _calculate_score(beta, max(20, age), clean_chol(chol_mmol),
                          clean_bp(sbp), smoking)
    return max(0, min(sc, 1))
예제 #12
0
def darts(diab_age, diab_dur, chol_tot, prev_smoker, cur_smoker, male, hba1c,
          follow5, sbp, htn, height, t):
    hba1c = clean_hba1c(hba1c)
    sbp = clean_bp(sbp)
    xFeat = np.array([
        np.log(clean_diab_dur(diab_dur)), diab_age,
        clean_tot_chol(chol_tot), prev_smoker, cur_smoker, male,
        np.log(hba1c),
        np.log(hba1c) * follow5, sbp, htn, sbp * htn,
        clean_height(height)
    ])
    s = weibull_atf_surv(xFeat, BETA, INTERCEPT, SIGMA, t)
    return s
예제 #13
0
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)
예제 #14
0
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"])
예제 #15
0
def ukpdsom2_stroke(diab_dur,
                    diab_age,
                    female,
                    afib,
                    egfr,
                    hba1c,
                    ldl,
                    mmalb,
                    sbp,
                    cur_smoke,
                    wbc,
                    amp_hist,
                    chd_hist,
                    tYear=1):
    """
    Calculate the number of years to forecast the risk.
    """
    xFeat = np.array([
        diab_age, female, afib, egfr / 10 if egfr < 60 else 0,
        clean_hba1c(hba1c), ldl * 10, mmalb >= 50,
        clean_bp(sbp) / 10, cur_smoke, wbc, amp_hist, chd_hist
    ])
    return weibull_surv(xFeat, STROKE_PARAMS["beta"], STROKE_PARAMS["lambda"],
                        diab_dur, diab_dur + tYear, STROKE_PARAMS["rho"])