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
Out[19]:
array([ 3.40119738,  3.11351531,  0.        ,  4.82831374,  0.        ,  0.        ])

Here is the corresponding risk scores (men and women)

In [20]:
frs_women(X=x_sample, b=betas)
Out[20]:
0.015094153510678776
In [21]:
frs_men(X=x_sample, b=betas)
Out[21]:
0.24491217871245496