Ejemplo n.º 1
0
def multiple_inverse(p_final, n):
    """Returns p_initial for desired p_final with n multiple comparisons.
    
    WARNING: multiple_inverse is not very reliable when p_final is very close
    to 1 (say, within 1e-4) since we then take the ratio of two very similar
    numbers.
    """
    return one_minus_exp(log_one_minus(p_final)/n)
Ejemplo n.º 2
0
def multiple_comparisons(p, n):
    """Corrects P-value for n multiple comparisons.
    
    Calculates directly if p is large and n is small; resorts to logs
    otherwise to avoid rounding (1-p) to 1
    """
    if p > 1e-6:   #if p is large and n small, calculate directly
        return 1 - (1-p)**n
    else:
        return one_minus_exp(-n * p)
Ejemplo n.º 3
0
 def test_one_minus_exp_small(self):
     """one_minus_exp_x should return -x if x is small"""
     self.assertFloatEqual(one_minus_exp(1e-30), -1e-30)
Ejemplo n.º 4
0
 def test_one_minus_exp_large(self):
     """one_minus_exp_x should return 1 - math.exp(x) if x is large"""
     self.assertFloatEqual(one_minus_exp(0.2), 1-(math.exp(0.2)))
Ejemplo n.º 5
0
 def test_one_minus_exp_small(self):
     """one_minus_exp_x should return -x if x is small"""
     self.assertFloatEqual(one_minus_exp(1e-30), -1e-30)
Ejemplo n.º 6
0
 def test_one_minus_exp_large(self):
     """one_minus_exp_x should return 1 - math.exp(x) if x is large"""
     self.assertFloatEqual(one_minus_exp(0.2), 1 - (math.exp(0.2)))