API Reference
Risk
- egfr40.egfr40_risk(age, male, egfr, uacr, sbp, bp_meds, hf, chd, afib, smoking, bmi, dm, hba1c=None, oral_dm=0, insulin=0, explain=False)[source]
3-year probability of a >=40% eGFR decline or kidney failure.
- Parameters:
age (float) – Age in years.
male (int) – 1 = male, 0 = female.
egfr (float) – eGFR in mL/min/1.73 m^2, from the CKD-EPI 2021 creatinine equation.
uacr (float) – Urine albumin-to-creatinine ratio in mg/g. Must be greater than 0.
sbp (float) – Systolic blood pressure in mmHg.
bp_meds (int) – Antihypertensive medication use (1/0).
hf (int) – History of heart failure (1/0).
chd (int) – History of coronary heart disease (1/0).
afib (int) – History of atrial fibrillation (1/0).
smoking ({'never', 'former', 'current'}) – Smoking status.
bmi (float) – Body mass index in kg/m^2.
dm (bool) – Diabetes. Required: selects the diabetes or no-diabetes model.
hba1c (float, optional) – HbA1c in percent. Required when
dmis True.oral_dm (int, default 0) – Oral diabetes medication (1/0). Used only when
dmis True.insulin (int, default 0) – Insulin use (1/0). Used only when
dmis True.explain (bool, default False) – Return a breakdown instead of just the risk.
- Returns:
The 3-year probability, between 0 and 1. At eGFR == 60 the two eGFR strata are averaged, as on ckdpcrisk.org.
With
explain=True, a dict withrisk,stratum,intercept,linear_predictor(log-odds) andcontributions(each predictor’s log-odds contribution, largest first). Positive contributions raise risk relative to the reference individual: age 60, eGFR at the stratum center (85 or 45), uACR 10 mg/g, SBP 130, BMI 30, HbA1c 7%, never smoker, no BP or diabetes medication, and HF and CHD at their centering values of 0.05 and 0.15 (so an individual without HF or CHD gets a small negative contribution for each). At eGFR == 60, a dict with the averagedriskand both breakdowns understrata.- Return type:
float or dict
- Raises:
ValueError – If
hba1cis missing for an individual with diabetes,uacris not positive, orsmokingis not a recognized value.
Examples
>>> egfr40_risk(age=70, male=1, egfr=40, uacr=150, sbp=140, bp_meds=1, ... hf=0, chd=1, afib=1, smoking="former", bmi=28, ... dm=True, hba1c=7) 0.166...
- egfr40.add_egfr40_risk_col(df, age_col='age', sex_col='sex', egfr_col='eGFR', uacr_col='uACR', sbp_col='sbp', bp_meds_col='bp_meds', hf_col='hf', chd_col='chd', afib_col='afib', smoking_col='smoking', bmi_col='bmi', dm_col='dm', hba1c_col='hba1c', oral_dm_col='oral_dm', insulin_col='insulin', risk_col='egfr40_3year', copy=True)[source]
Add the 3-year >=40% eGFR decline risk to every row of a DataFrame.
Each row is scored with its own stratum (eGFR >=60 or <60, with or without diabetes). Rows at exactly eGFR 60 get the average of the two eGFR strata, as on ckdpcrisk.org.
- Parameters:
df (pandas.DataFrame) – One row per individual.
age_col (str) – Column names for age (years), sex, eGFR (CKD-EPI 2021), uACR (mg/g), systolic BP (mmHg) and antihypertensive medication use.
sex_col (str) – Column names for age (years), sex, eGFR (CKD-EPI 2021), uACR (mg/g), systolic BP (mmHg) and antihypertensive medication use.
egfr_col (str) – Column names for age (years), sex, eGFR (CKD-EPI 2021), uACR (mg/g), systolic BP (mmHg) and antihypertensive medication use.
uacr_col (str) – Column names for age (years), sex, eGFR (CKD-EPI 2021), uACR (mg/g), systolic BP (mmHg) and antihypertensive medication use.
sbp_col (str) – Column names for age (years), sex, eGFR (CKD-EPI 2021), uACR (mg/g), systolic BP (mmHg) and antihypertensive medication use.
bp_meds_col (str) – Column names for age (years), sex, eGFR (CKD-EPI 2021), uACR (mg/g), systolic BP (mmHg) and antihypertensive medication use.
hf_col (str) – Column names for history of heart failure, coronary heart disease and atrial fibrillation.
chd_col (str) – Column names for history of heart failure, coronary heart disease and atrial fibrillation.
afib_col (str) – Column names for history of heart failure, coronary heart disease and atrial fibrillation.
smoking_col (str) – Column names for smoking status and BMI (kg/m^2).
bmi_col (str) – Column names for smoking status and BMI (kg/m^2).
dm_col (str) – Column names for diabetes, HbA1c (%), oral diabetes medication and insulin. The last three are used only for rows with diabetes and may be absent from
dfif no row has diabetes.hba1c_col (str) – Column names for diabetes, HbA1c (%), oral diabetes medication and insulin. The last three are used only for rows with diabetes and may be absent from
dfif no row has diabetes.oral_dm_col (str) – Column names for diabetes, HbA1c (%), oral diabetes medication and insulin. The last three are used only for rows with diabetes and may be absent from
dfif no row has diabetes.insulin_col (str) – Column names for diabetes, HbA1c (%), oral diabetes medication and insulin. The last three are used only for rows with diabetes and may be absent from
dfif no row has diabetes.risk_col (str, default "egfr40_3year") – Name of the new risk column.
copy (bool, default True) – Work on a copy and leave
dfunchanged.
- Returns:
df(or a copy) withrisk_coladded, holding probabilities between 0 and 1.- Return type:
pandas.DataFrame
Notes
Sex accepts
"male"/"female","m"/"f"or 1/0. Yes/no columns (BP medication, HF, CHD, AFib, diabetes, oral diabetes medication, insulin) accept 1/0 or"yes"/"no". Smoking accepts"never","former"or"current".A row with any required input missing gets
NaN. HbA1c, oral diabetes medication and insulin are required only for rows with diabetes; missing values there giveNaNrather than being treated as 0.- Raises:
ValueError – If a smoking or yes/no column contains an unrecognized value.
eGFR
- egfr40.ckd_epi_2021(scr, age, male)[source]
eGFR from serum creatinine, using the CKD-EPI 2021 (race-free) equation.
Inker LA et al. N Engl J Med 2021;385:1737-1749.
- Parameters:
scr (float or array-like) – Serum creatinine in mg/dL.
age (float or array-like) – Age in years.
male (int or array-like) – 1 = male, 0 = female.
- Returns:
eGFR in mL/min/1.73 m^2. NaN where inputs are missing.
- Return type:
float or numpy.ndarray
Examples
>>> round(ckd_epi_2021(scr=1.0, age=50, male=1), 1) 91.7
Conversions
- egfr40.pcr_to_acr(pcr)[source]
Estimate uACR from the urine protein-to-creatinine ratio (uPCR).
Uses the crude equation of Sumida et al. (2020): exp(5.3920 + 0.3072 log(min(PCR/50, 1)) + 1.5793 log(max(min(PCR/500, 1), 0.1)) + 1.1266 log(max(PCR/500, 1))).
- Parameters:
pcr (float or array-like) – uPCR in mg/g.
- Returns:
Estimated uACR in mg/g. NaN for missing or non-positive uPCR.
- Return type:
float or numpy.ndarray
Examples
>>> round(pcr_to_acr(150), 1) 32.8
- egfr40.dipstick_to_acr(category)[source]
Estimate uACR from a urine dipstick protein category.
Uses the crude equation of Sumida et al. (2020).
- Parameters:
category (str or list of str) –
"negative","trace","+","++"or">++". Also accepts"neg","1+","2+","3+","4+"and"+++".- Returns:
Estimated uACR in mg/g. NaN for missing values.
- Return type:
float or numpy.ndarray
- Raises:
ValueError – If a category is not recognized.
Examples
>>> round(dipstick_to_acr("++"), 1) 337.4