From efd04205b9262a7771e467627252532b9db8136d Mon Sep 17 00:00:00 2001 From: Steve Morley Date: Tue, 29 May 2018 13:38:45 -0600 Subject: [PATCH] verify, test_verify: fixed odds ratio (and subsequent Yule's Q calc) --- test_verify.py | 10 ++++++++++ verify.py | 4 +++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/test_verify.py b/test_verify.py index 1f63680..2909901 100644 --- a/test_verify.py +++ b/test_verify.py @@ -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) diff --git a/verify.py b/verify.py index c466f5b..6513397 100644 --- a/verify.py +++ b/verify.py @@ -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']