#!/usr/bin/env python # coding: utf-8 # In[1]: import numpy as np # I will implement the 10-year risk equation for women. Here are the betas. # In[2]: betas = np.array([2.72107, # log age 0.51125, # log BMI 2.81291, # log SBP (not treated) 2.88267, # log SBP (treated) 0.61868, # smoking 0.77763, # diabetes ]) # Here is the formula. The `dot` function is the dot product, or inner product of the coefficients and the data array (i.e. multiply them element-wise, and add the products) # In[16]: def frs(X, b, surv, const): return 1 - surv** np.exp(X.dot(b) - const) # Below are special cases of the general formula, using the survival and constants specified for men and women: # In[17]: def frs_women(X, b): return frs(X, b, 0.94833, 26.0145) # In[18]: def frs_men(X, b): return frs(X, b, 0.88431, 23.9388) # Here is some sample data # In[19]: x_sample = np.array([np.log(30), np.log(22.5), 0, np.log(125), 0, 0]) x_sample # Here is the corresponding risk scores (men and women) # In[20]: frs_women(X=x_sample, b=betas) # In[21]: frs_men(X=x_sample, b=betas)