import numpy as np
I will implement the 10-year risk equation for women. Here are the betas.
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)
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:
def frs_women(X, b):
return frs(X, b, 0.94833, 26.0145)
def frs_men(X, b):
return frs(X, b, 0.88431, 23.9388)
Here is some sample data
x_sample = np.array([np.log(30), np.log(22.5), 0, np.log(125), 0, 0])
x_sample
array([ 3.40119738, 3.11351531, 0. , 4.82831374, 0. , 0. ])
Here is the corresponding risk scores (men and women)
frs_women(X=x_sample, b=betas)
0.015094153510678776
frs_men(X=x_sample, b=betas)
0.24491217871245496