Ejemplo n.º 1
0
 def test_chisq2(self):
     """constrtucted from 2D dict"""
     data = {
         "rest_of_tree": {
             "env1": 2,
             "env3": 1,
             "env2": 0
         },
         "b": {
             "env1": 1,
             "env3": 1,
             "env2": 3
         },
     }
     table = CategoryCounts(data)
     got = table.chisq_test()
     assert_allclose(got.chisq, 3.02222222)
     data = {
         "AIDS": {
             "Males": 4,
             "Females": 2,
             "Both": 3
         },
         "No_AIDS": {
             "Males": 3,
             "Females": 16,
             "Both": 2
         },
     }
     table = CategoryCounts(data)
     got = table.chisq_test()
     assert_allclose(got.chisq, 7.6568405139833722)
     assert_allclose(got.pvalue, 0.0217439383468)
Ejemplo n.º 2
0
 def test_shuffling(self):
     """resampling works for G-independence"""
     table = CategoryCounts([[762, 327], [750, 340]])
     got = table.G_independence(shuffled=50)
     self.assertTrue(0 < got.pvalue < 1)  # a large interval
     got = table.chisq_test(shuffled=50)
     self.assertTrue(0 < got.pvalue < 1)  # a large interval
Ejemplo n.º 3
0
 def test_chisq(self):
     """correctly compute chisq test"""
     table = CategoryCounts([[762, 327, 468], [484, 239, 477]])
     got = table.chisq_test()
     self.assertEqual(round(got.chisq, 5), 30.07015)
     self.assertEqual(got.df, 2)
     assert_allclose(got.pvalue, 2.95358918321e-07)
Ejemplo n.º 4
0
 def test_1D_counts(self):
     """correctly operate on a 1D count array"""
     table = CategoryCounts([762, 327])
     got = table.chisq_test()
     assert_allclose(got.chisq, 173.7603305785124)
     self.assertLess(got.pvalue, 2.2e-16)  # value from R
     _ = got._repr_html_()  # shouldn't fail
     self.assertIn("1.12e-39", str(got))  # used sci formatting
Ejemplo n.º 5
0
 def test_repr_str_html(self):
     """exercising construction of different representations"""
     table = CategoryCounts(
         {
             "rest_of_tree": {"env1": 2, "env3": 1, "env2": 0},
             "b": {"env1": 1, "env3": 1, "env2": 3},
         }
     )
     got_g1 = table.G_fit()
     got_g2 = table.G_independence()
     got_chisq = table.chisq_test()
     for obj in (got_g1, got_g2, got_chisq):
         str(obj)
         repr(obj)
         obj._repr_html_()
Ejemplo n.º 6
0
 def test_statistics(self):
     """returns TestResult.statistics has stats"""
     table = CategoryCounts({
         "rest_of_tree": {
             "env1": 2,
             "env3": 1,
             "env2": 0
         },
         "b": {
             "env1": 1,
             "env3": 1,
             "env2": 3
         },
     })
     got = table.chisq_test()
     stats = got.statistics
     self.assertEqual(stats[0, "pvalue"], got.pvalue)
Ejemplo n.º 7
0
 def test_1D_counts(self):
     """correctly operate on a 1D count array"""
     table = CategoryCounts([762, 327])
     got = table.chisq_test()
     assert_allclose(got.chisq, 173.7603305785124)
     self.assertLess(got.pvalue, 2.2e-16)  # value from R