-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathodds6.py
More file actions
35 lines (30 loc) · 1.1 KB
/
odds6.py
File metadata and controls
35 lines (30 loc) · 1.1 KB
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
# wrote by Ma Ruiqiang and Hiroaki Kikuchi, 2021
#!/usr/bin/env python
# coding: utf-8
import pandas as pd
import numpy as np
import statsmodels.api as sm # LR
import statsmodels.formula.api as smf
import sys
def odds(df):
df.columns = ['gen', 'age', 'race', 'edu', 'mar', 'bmi', 'dep', 'pir', 'gh', 'mets', 'qm', 'dia']
model = smf.glm(formula='dia ~ gen + age + race + edu + mar + bmi + dep + pir + qm', data=df, family= sm.families.Binomial() )
res = model.fit()
# Odds Ratio, Confidence Intervals and Pvalues
df2 = pd.DataFrame(res.params, columns=['Coef'])
df2['OR'] = np.exp(res.params)
df2['pvalue'] = res.pvalues
return(df2)
def mae(dfB, dfD):
dfBOR = odds(dfB)['OR']
dfDOR = odds(dfD)['OR']
return ((dfBOR - dfDOR).abs().max(), (dfBOR - dfDOR).abs().mean())
if __name__== "__main__":
args = sys.argv
if len(args) != 2:
print(args[0], ' diabets.csv d-rr8.csv [or.csv]')
dfB = pd.read_csv(args[1], header=None)
dfD = pd.read_csv(args[2], header=None)
#dfBOR = odds(dfB)['Odds_Ratio']
#dfDOR = odds(dfD)['Odds_Ratio']
print(mae(dfB, dfD))