-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNNT_ARR.py
40 lines (28 loc) · 1.12 KB
/
NNT_ARR.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#Numbers Needed to Treat / Absolute Risk Reduction Calculation
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 08 21:39:08 2017
@author: OnoTation
"""
#import library
import pandas as pd
#csv as df
pd.set_option('precision', 0)
df = pd.read_csv('file:///C:/Users/Onotation/Desktop/allMalignantCancerRange_newDB.csv')
df.values
#group by unique age groups
ages= df.AgeGroups.unique()
#group by agegroups, factor, cancer
grp = df.groupby(['AgeGroups','Factor','Cancer']).Frequency.sum()
counts = grp.unstack(level=[2])
counts['sumwwoCancer']= counts['No']+counts['Yes']
#calculate cumulative incidence
test= counts['cumInci']=((counts['Yes']/counts['sumwwoCancer'])*100)
testUnstacked = test.unstack(level=[1])
#calculate absolute risk ratio
ok=testUnstacked['AbsoluteRR']= (testUnstacked['wo-statin']-testUnstacked['w-statin'])
testUnstacked['NNT'] = 1/testUnstacked['AbsoluteRR']
#testUnstacked.NNT = testUnstacked.NNT.round()
#testUnstacked.NNT = np.ceil(testUnstacked.NNT)
#print the numbers needed to treat
print ("Number Needed to Treat for each of the", testUnstacked['NNT']*100)