Skip to content

Commit

Permalink
verify, test_verify: fixed odds ratio (and subsequent Yule's Q calc)
Browse files Browse the repository at this point in the history
  • Loading branch information
drsteve committed May 29, 2018
1 parent 717c24a commit efd0420
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
10 changes: 10 additions & 0 deletions test_verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@ def test_MatthewsCC_known2(self):
ctab = verify.Contingency2x2([[0, 24], [327, 0]])
self.assertEqual(ctab.MatthewsCC(), -1)

def test_oddsRatio_known(self):
'''Test Odds ratio calculation with example given by Thornes and Stephenson'''
ctab = verify.Contingency2x2([[29, 6], [4, 38]])
self.assertAlmostEqual(ctab.oddsRatio(), 45.9, places=1)

def test_YuleQ_known(self):
'''Test Yule's Q (ORSS) calculation with example given by Thornes and Stephenson'''
ctab = verify.Contingency2x2([[29, 6], [4, 38]])
self.assertAlmostEqual(ctab.yuleQ(), 0.96, places=2)

def test_Finley_n(self):
ctab = verify.Contingency2x2(self.Finley)
self.assertEqual(ctab.sum(), 2803)
Expand Down
4 changes: 3 additions & 1 deletion verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -1175,7 +1175,9 @@ def oddsRatio(self):
This is also added to the attrs attribute of the table object
'''
a,b,c,d = self._abcd()
odds = a*d/b*c
numer = a*d
denom = b*c
odds = numer/denom

self.attrs['OddsRatio'] = odds
return self.attrs['OddsRatio']
Expand Down

0 comments on commit efd0420

Please # to comment.