Example #1
0
 def test_chi_square_from_Dict2D(self):
     """chi_square_from_Dict2D calcs a Chi-Square and p value from Dict2D"""
     #test1
     obs_matrix = Dict2D({'rest_of_tree': {'env1': 2, 'env3': 1, 'env2': 0},
               'b': {'env1': 1, 'env3': 1, 'env2': 3}})
     input_matrix = calc_contingency_expected(obs_matrix)
     test, csp = chi_square_from_Dict2D(input_matrix)
     self.assertFloatEqual(test, 3.0222222222222221)
     #test2
     test_matrix_2 = Dict2D({'Marl': {'val':[2, 5.2]},
                             'Chalk': {'val':[10, 5.2]},
                             'Sandstone':{'val':[8, 5.2]},
                             'Clay':{'val':[2, 5.2]},
                             'Limestone':{'val':[4, 5.2]}
                             })
     test2, csp2 = chi_square_from_Dict2D(test_matrix_2)
     self.assertFloatEqual(test2, 10.1538461538)
     self.assertFloatEqual(csp2, 0.0379143890013)
     #test3
     matrix3_obs = Dict2D({'AIDS':{'Males':4, 'Females':2, 'Both':3},
                     'No_AIDS':{'Males':3, 'Females':16, 'Both':2}
                    })
     matrix3 = calc_contingency_expected(matrix3_obs)
     test3, csp3 = chi_square_from_Dict2D(matrix3)
     self.assertFloatEqual(test3, 7.6568405139833722)
     self.assertFloatEqual(csp3, 0.0217439383468)
Example #2
0
 def test_chi_square_from_Dict2D(self):
     """chi_square_from_Dict2D calcs a Chi-Square and p value from Dict2D"""
     #test1
     obs_matrix = Dict2D({
         'rest_of_tree': {
             'env1': 2,
             'env3': 1,
             'env2': 0
         },
         'b': {
             'env1': 1,
             'env3': 1,
             'env2': 3
         }
     })
     input_matrix = calc_contingency_expected(obs_matrix)
     test, csp = chi_square_from_Dict2D(input_matrix)
     self.assertFloatEqual(test, 3.0222222222222221)
     #test2
     test_matrix_2 = Dict2D({
         'Marl': {
             'val': [2, 5.2]
         },
         'Chalk': {
             'val': [10, 5.2]
         },
         'Sandstone': {
             'val': [8, 5.2]
         },
         'Clay': {
             'val': [2, 5.2]
         },
         'Limestone': {
             'val': [4, 5.2]
         }
     })
     test2, csp2 = chi_square_from_Dict2D(test_matrix_2)
     self.assertFloatEqual(test2, 10.1538461538)
     self.assertFloatEqual(csp2, 0.0379143890013)
     #test3
     matrix3_obs = Dict2D({
         'AIDS': {
             'Males': 4,
             'Females': 2,
             'Both': 3
         },
         'No_AIDS': {
             'Males': 3,
             'Females': 16,
             'Both': 2
         }
     })
     matrix3 = calc_contingency_expected(matrix3_obs)
     test3, csp3 = chi_square_from_Dict2D(matrix3)
     self.assertFloatEqual(test3, 7.6568405139833722)
     self.assertFloatEqual(csp3, 0.0217439383468)
def run_single_G_test(OTU_name, category_info, otu_table, category_values,
                      suppress_warnings=False):
    """run the G test on a single OTU
       If suppress_warnings=True, doesn't warn when sample in map but not otu table
    """
    contingency_matrix = make_contingency_matrix(OTU_name, category_info, \
        otu_table, category_values, suppress_warnings=suppress_warnings)
    contingency_matrix = calc_contingency_expected(contingency_matrix)
    g_val, prob = G_fit_from_Dict2D(contingency_matrix)
    return g_val, prob, contingency_matrix
Example #4
0
 def test_calc_contingency_expected(self):
     """calcContingencyExpected returns new matrix with expected freqs"""
     matrix = Dict2D({'rest_of_tree': {'env1': 2, 'env3': 1, 'env2': 0},
               'b': {'env1': 1, 'env3': 1, 'env2': 3}})
     result = calc_contingency_expected(matrix)
     self.assertFloatEqual(result['rest_of_tree']['env1'], [2, 1.125])
     self.assertFloatEqual(result['rest_of_tree']['env3'], [1, 0.75])
     self.assertFloatEqual(result['rest_of_tree']['env2'], [0, 1.125])
     self.assertFloatEqual(result['b']['env1'], [1, 1.875])
     self.assertFloatEqual(result['b']['env3'], [1, 1.25])
     self.assertFloatEqual(result['b']['env2'], [3, 1.875])
Example #5
0
def run_single_G_test(OTU_name,
                      category_info,
                      otu_sample_info,
                      category_values,
                      suppress_warnings=False):
    """run the G test on a single OTU
       If suppress_warnings=True, doesn't warn when sample in map but not otu table
    """
    contingency_matrix = make_contingency_matrix(OTU_name, category_info, \
        otu_sample_info, category_values, suppress_warnings=suppress_warnings)
    contingency_matrix = calc_contingency_expected(contingency_matrix)
    g_val, prob = G_fit_from_Dict2D(contingency_matrix)
    return g_val, prob, contingency_matrix
Example #6
0
 def test_calc_contingency_expected(self):
     """calcContingencyExpected returns new matrix with expected freqs"""
     matrix = Dict2D({
         'rest_of_tree': {
             'env1': 2,
             'env3': 1,
             'env2': 0
         },
         'b': {
             'env1': 1,
             'env3': 1,
             'env2': 3
         }
     })
     result = calc_contingency_expected(matrix)
     self.assertFloatEqual(result['rest_of_tree']['env1'], [2, 1.125])
     self.assertFloatEqual(result['rest_of_tree']['env3'], [1, 0.75])
     self.assertFloatEqual(result['rest_of_tree']['env2'], [0, 1.125])
     self.assertFloatEqual(result['b']['env1'], [1, 1.875])
     self.assertFloatEqual(result['b']['env3'], [1, 1.25])
     self.assertFloatEqual(result['b']['env2'], [3, 1.875])