From 77f1e787fc6740d6e00873523823d50262fcaae5 Mon Sep 17 00:00:00 2001 From: Marco Biasini <mvbiasini@gmail.com> Date: Mon, 13 Aug 2012 09:19:59 +0200 Subject: [PATCH] added paired T-test to table class --- modules/base/pymod/table.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/modules/base/pymod/table.py b/modules/base/pymod/table.py index cb505d3ae..11f8285d6 100644 --- a/modules/base/pymod/table.py +++ b/modules/base/pymod/table.py @@ -498,6 +498,27 @@ Statistics for column %(col)s if not overwrite or not added: self.rows.append(new_row) + def PairedTTest(self, col_a, col_b): + """ + Two-sided test for the null-hypothesis that two related samples + have the same average (expected values) + + :param col_a: First column + :param col_b: Second column + + :returns: P-value between 0 and 1 that the two columns have the + same average. The smaller the value, the less related the two + columns are. + """ + from scipy.stats import ttest_rel + xs = [] + ys = [] + for x, y in self.Zip(col_a, col_b): + if x!=None and y!=None: + xs.append(x) + ys.append(y) + result = ttest_rel(xs, ys) + return result[1] def AddRow(self, data, overwrite=None): """ -- GitLab