-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmcnemar.py
53 lines (46 loc) · 1.12 KB
/
mcnemar.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
41
42
43
44
45
46
47
48
49
50
51
52
import sys
import pdb
import rpy2.robjects as ro
def lines_right(line1, line2):
if line1[1] == line1[2]:
l1_right = True
else:
l1_right = False
if line2[1] == line2[2]:
l2_right = True
else:
l2_right = False
return l1_right, l2_right
both_right = 0
both_wrong = 0
only_1_right = 0
only_2_right = 0
for line1, line2 in zip(open(sys.argv[1], 'r'), open(sys.argv[2], 'r')):
line1 = line1.strip().split('\t')
line2 = line2.strip().split('\t')
results = lines_right(line1, line2)
if results == (False, False):
both_wrong += 1
elif results == (True, False):
only_1_right += 1
elif results == (False, True):
only_2_right += 1
elif results == (True, True):
both_right += 1
else:
print('ERROR\n', line1, '\n', line2)
"""
r stuff:
x = matrix(c(1,2,3,4), 2, 2)
mcnemar.test(x)
"""
rstring = "mcnemar.test(matrix(c("
rstring += str(both_right)
rstring += ", "
rstring += str(only_1_right)
rstring += ", "
rstring += str(only_2_right)
rstring += ", "
rstring += str(both_wrong)
rstring += "), 2, 2))"
print(ro.r(rstring))