def test_t_paired_specific_difference(self): """t_paired should allow a specific difference to be passed""" x, y = self.x, self.y #difference is 0.2, so test should be non-significant if 0.2 passed self.failIf(t_paired(y, x, exp_diff=0.2)[0] > 1e-10) #same, except that reversing list order reverses sign of difference self.failIf(t_paired(x, y, exp_diff=-0.2)[0] > 1e-10) #check that there's no significant difference from the true mean self.assertFloatEqual(t_paired(y, x, exp_diff=0.2)[1], 1, 1e-4)
def test_t_paired_specific_difference(self): """t_paired should allow a specific difference to be passed""" x, y = self.x, self.y #difference is 0.2, so test should be non-significant if 0.2 passed self.failIf(t_paired(y, x, exp_diff=0.2)[0] > 1e-10) #same, except that reversing list order reverses sign of difference self.failIf(t_paired(x, y, exp_diff=-0.2)[0] > 1e-10) #check that there's no significant difference from the true mean self.assertFloatEqual( t_paired(y, x,exp_diff=0.2)[1], 1, 1e-4)
def test_t_paired_1tailed(self): """t_paired should match pre-calculated 1-tailed values""" x, y = self.x, self.y #check probability for 1-tailed low and high self.assertFloatEqual( t_paired(y, x, "low")[1], 1 - (1.301439e-11 / 2), 1e-4) self.assertFloatEqual( t_paired(x, y, "high")[1], 1 - (1.301439e-11 / 2), 1e-4) self.assertFloatEqual( t_paired(y, x, "high")[1], 1.301439e-11 / 2, 1e-4) self.assertFloatEqual(t_paired(x, y, "low")[1], 1.301439e-11 / 2, 1e-4)
def test_t_paired_1tailed(self): """t_paired should match pre-calculated 1-tailed values""" x, y = self.x, self.y #check probability for 1-tailed low and high self.assertFloatEqual( t_paired(y, x, "low")[1], 1-(1.301439e-11/2), 1e-4) self.assertFloatEqual( t_paired(x, y, "high")[1], 1-(1.301439e-11/2), 1e-4) self.assertFloatEqual( t_paired(y, x, "high")[1], 1.301439e-11/2, 1e-4) self.assertFloatEqual( t_paired(x, y, "low")[1], 1.301439e-11/2, 1e-4)
def run_single_paired_T_test(OTU, mapping_data, header, individual_column,\ timepoint_zero_column, otu_ids, sample_ids, otu_counts, ignore_val, filter): """run the paired T test on a single OTU """ timepoint_zero_vals, after_treatment_vals = get_single_paired_T_values(OTU,\ mapping_data, header, individual_column, timepoint_zero_column, otu_ids,\ sample_ids, otu_counts, ignore_val) if len(timepoint_zero_vals) * 2 >= int(filter): t, prob = t_paired(timepoint_zero_vals, after_treatment_vals, tails=None, \ exp_diff=0) return t, prob, after_treatment_vals, len(after_treatment_vals) else: return None
def run_single_paired_T_test(OTU, mapping_data, header, individual_column,\ timepoint_zero_column, otu_table, ignore_val, filt): """run the paired T test on a single OTU """ timepoint_zero_vals, after_treatment_vals = get_single_paired_T_values(OTU, mapping_data, header, individual_column, timepoint_zero_column, otu_table, ignore_val) #get the number of samples from the category mapping and multiply by the filter #two samples per individual so divide by 2 filt = (filt*len(mapping_data))/2 if len(timepoint_zero_vals) >= round(filt): t, prob = t_paired(timepoint_zero_vals, after_treatment_vals, tails=None, exp_diff=0) return t, prob, after_treatment_vals, len(after_treatment_vals) else: return None
def run_single_paired_T_test(OTU, mapping_data, header, individual_column,\ timepoint_zero_column, otu_table, ignore_val, filt): """run the paired T test on a single OTU """ timepoint_zero_vals, after_treatment_vals = get_single_paired_T_values( OTU, mapping_data, header, individual_column, timepoint_zero_column, otu_table, ignore_val) #get the number of samples from the category mapping and multiply by the filter #two samples per individual so divide by 2 filt = (filt * len(mapping_data)) / 2 if len(timepoint_zero_vals) >= round(filt): t, prob = t_paired(timepoint_zero_vals, after_treatment_vals, tails=None, exp_diff=0) return t, prob, after_treatment_vals, len(after_treatment_vals) else: return None
def test_t_paired_no_variance(self): """t_paired should return None if lists are invariant""" x = [1, 1, 1] y = [0, 0, 0] self.assertEqual(t_paired(x,x), (None, None)) self.assertEqual(t_paired(x,y), (None, None))
def test_t_paired_2tailed(self): """t_paired should match values from Sokal & Rohlf p 353""" x, y = self.x, self.y #check value of t and the probability for 2-tailed self.assertFloatEqual(t_paired(y, x)[0], 19.7203, 1e-4) self.assertFloatEqual(t_paired(y, x)[1], 1.301439e-11, 1e-4)
def test_t_paired_no_variance(self): """t_paired should return None if lists are invariant""" x = [1, 1, 1] y = [0, 0, 0] self.assertEqual(t_paired(x, x), (None, None)) self.assertEqual(t_paired(x, y), (None, None))