def testFishers(self): """Verify computation of Fisher's exact test (minimum-likelihood approach)""" from plugins.statisticalTests.Fishers import Fishers fishers = Fishers(preferences) # Ground truth obtained from R version 2.10 oneSided, twoSided = fishers.hypothesisTest(table1[0], table1[1], table1[2], table1[3]) self.assertAlmostEqual(oneSided, 0.16187126209690825) self.assertAlmostEqual(twoSided, 0.2715543327789185) oneSided, twoSided = fishers.hypothesisTest(table2[0], table2[1], table2[2], table2[3]) self.assertAlmostEqual(oneSided, 2.220446049e-16) self.assertAlmostEqual(twoSided, 2.220446049e-16)
from plugins.statisticalTests.Fishers import Fishers preferences = {} fishers = Fishers(preferences) sampleSizes = [ 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000, 20000, 50000, 100000 ] fout = open('effectSizeTest.txt', 'w') for sampleSize in sampleSizes: print sampleSize a = sampleSize / 2 b = sampleSize / 2 pValueTwoSided = 1.0 while pValueTwoSided > 0.05: pValueOneSided, pValueTwoSided = fishers.hypothesisTest( a, b, sampleSize, sampleSize) a += 1 p1 = float(a) / sampleSize p2 = float(b) / sampleSize fout.write( str(sampleSize) + ',' + str(p1 - p2) + ',' + str(p1 / p2) + ',' + str(pValueTwoSided) + ',' + str(a) + '\n')
import math import random from plugins.statisticalTests.Fishers import Fishers from plugins.statisticalTests.Hypergeometric import Hypergeometric fishers = Fishers({}) hypergeometric = Hypergeometric({}) C1s = [1000, 10000, 100000] maxX1 = 200 def mean(x): if len(x) == 0: return 0 sum = 0.0 for i in xrange(0, len(x)): sum += x[i] return sum / len(x) def stdDev(x): if len(x) == 0: return 0 m = mean(x) sumsq = 0.0 for i in xrange(0, len(x)): sumsq += (x[i] - m) * (x[i] - m)