Example #1
0
 def test2(self):
     np.testing.assert_almost_equal(funcs.normal_cdf(1.69), .95, 2)
     np.testing.assert_almost_equal(funcs.normal_cdf(-1.69), .05, 2)
     np.testing.assert_almost_equal(funcs.normal_probability_below(1.69),
                                    .95, 2)
     np.testing.assert_almost_equal(funcs.normal_probability_above(1.69),
                                    .05, 2)
Example #2
0
def p_value(beta_hat_j, sigma_hat_j):
    """if the coefficient is positive, we need to compute twice the
    probability of seeing an even larger value; otherwise twice the
    probability of seeing a smaller value"""
    if beta_hat_j > 0:
        return 2 * (1 - probability.normal_cdf(beta_hat_j / sigma_hat_j))
    else:
        return 2 * probability.normal_cdf(beta_hat_j / sigma_hat_j)
def p_value(beta_hat_j, sigma_hat_j):
    """if the coefficient is positive, we need to compute twice the
    probability of seeing an even larger value; otherwise twice the
    probability of seeing a smaller value"""
    if beta_hat_j > 0:
        return 2 * (1 - probability.normal_cdf(beta_hat_j / sigma_hat_j))
    else:
        return 2 * probability.normal_cdf(beta_hat_j / sigma_hat_j)
def p_value(beta_hat_j, sigma_hat_j):
    if beta_hat_j > 0:
        # if the coefficient is positive, we need to compute twice the
        # probability of seeing an even *larger* return
        return 2 * (1 - normal_cdf(beta_hat_j / simga_hat_j))
    else:
        # otherwise twice the probability of seeing a *smaller* value
        return 2 * normal_cdf(beta_hat_j / sigma_hat_j)
def p_value(beta_hat_j: float, sigma_hat_j: float) -> float:
    if beta_hat_j > 0:
        #if the coefficient is positive, we need to compute
        #twice the probability of seeing an even larger value"""
        return 2*(1-normal_cdf(beta_hat_j/sigma_hat_j))
        #"""Otherwise twice the probability of a smaller value"""
    else:
        return 2*(normal_cdf(beta_hat_j/sigma_hat_j))
Example #6
0
def p_value(beta_hat_i: float, sigma_hat_i: float) -> float:
    """
    return the probabity estimate that we would observe this parameter beta given the 
    standard error if the true value of beta is zero
    """
    if beta_hat_i > 0:
        positive_tail = 1 - normal_cdf(
            beta_hat_i /
            sigma_hat_i)  # probability that X ~ Normal(0, 1) > beta_hat_i
        return 2 * positive_tail  # we're asking about absolute deviation
    else:
        negative_tail = normal_cdf(
            beta_hat_i /
            sigma_hat_i)  # probability that X ~ Normal(0, 1) > beta_hat_i
        return 2 * negative_tail  # we're asking about absolute deviation
Example #7
0
def plot_normal_cdfs(plt):
    xs = [x / 10.0 for x in range(-50, 50)]
    plt.plot(xs, [normal_cdf(x, sigma=1) for x in xs],
             '-',
             label='mu=0,sigma=1')
    plt.plot(xs, [normal_cdf(x, sigma=2) for x in xs],
             '--',
             label='mu=0,sigma=2')
    plt.plot(xs, [normal_cdf(x, sigma=0.5) for x in xs],
             ':',
             label='mu=0,sigma=0.5')
    plt.plot(xs, [normal_cdf(x, mu=-1) for x in xs],
             '-.',
             label='mu=-1,sigma=1')
    plt.legend(loc=4)  # bottom right
    plt.show()
Example #8
0
def p_value(beta_hat_j, sigma_hat_j):
    if beta_hat_j > 0:
        return 2 * (1 - normal_cdf(beta_hat_j / sigma_hat_j))
    else:
        return 2 * normal_cdf(beta_hat_j / sigma_hat_j)
def p_value(beta_hat_j, sigma_hat_j):
    if beta_hat_j > 0:
        return 2 * (1 - normal_cdf(beta_hat_j / sigma_hat_j))
    else:
        return 2 * normal_cdf(beta_hat_j / sigma_hat_j)
 def test_normal_cdf(self):
     self.assertEqual((1 + math.erf(0)) / 2,
                      probability.normal_cdf(0, mu=0, sigma=1))
     self.assertEqual((1 + math.erf(-1 / (3 * math.sqrt(2)))) / 2,
                      probability.normal_cdf(1, mu=2, sigma=3))
def normal_probability_above(lo, mu=0, sigma=1):
    return 1 - normal_cdf(lo, mu, sigma)
def normal_probability_between(lo: float,
                               hi: float,
                               mu: float = 0,
                               sigma: float = 1) -> float:
    """The probability than an N(mu, sigma) is between lo and hi."""
    return normal_cdf(hi, mu, sigma) - normal_cdf(lo, mu, sigma)
def normal_probability_above(lo: float,
                             mu: float = 0,
                             sigma: float = 1) -> float:
    """The probability that an N(mu, sigma) is greater than lo"""
    return 1 - normal_cdf(lo, mu, sigma)
Example #14
0
def normal_probability_between(lo, hi, mu=0, sigma=1):
    """between if less than hi but not less than lo"""
    return normal_cdf(hi, mu, sigma) - normal_cdf(lo, mu, sigma)
Example #15
0
def normal_probability_above(lo, mu=0, sigma=1):
    """above if it's not below the threshold"""
    return 1 - normal_cdf(lo, mu, sigma)
Example #16
0
 def test4(self):
     np.testing.assert_almost_equal(funcs.normal_cdf(2), .97, 2)
     np.testing.assert_almost_equal(funcs.normal_cdf(0), .5, 2)
     np.testing.assert_almost_equal(funcs.normal_cdf(-2), .03, 2)
Example #17
0
def normal_probability_above(lo, mu=0, sigma=1):
    return 1 - normal_cdf(lo, mu, sigma)
Example #18
0
def normal_probability_between(lo, hi, mu=0, sigma=1):
    return normal_cdf(hi, mu, sigma) - normal_cdf(lo, mu, sigma)
Example #19
0
import random
from collections import Counter

smooth = 10.0
i_s = []
for j in range(1000):
    i = random.randint(-50, 50)
    i_s.append(i / smooth)

i_s.sort()
pdf_s = []
cdf_s = []
hst_s = []
for i in i_s:
    pdf_s.append(probability.normal_pdf(i))
    cdf_s.append(probability.normal_cdf(i))
    hst_s.append(probability.binomial(0.75, 100))

plt.plot(i_s, pdf_s)
plt.show()

plt.plot(i_s, cdf_s)
plt.show()

gmrHist = Counter(hst_s)
plt.bar(gmrHist.keys(), gmrHist.values())
plt.show()

smooth = 2.0
i_s = []
for j in range(1000):
def normal_probability_between(lo, hi, mu=0, sigma=1):
    return normal_cdf(hi, mu, sigma) - normal_cdf(lo, mu, sigma)
 def test_normal_cdf(self):
     self.assertEqual((1 + math.erf(0)) / 2, probability.normal_cdf(0, mu=0, sigma=1))
     self.assertEqual((1 + math.erf(-1 / (3 * math.sqrt(2)))) / 2, probability.normal_cdf(1, mu=2, sigma=3))
def normal_probability_above(lo: float,
                             mu: float = 0,
                             sigma: float = 1) -> float:
    return 1 - normal_cdf(lo, mu, sigma)
def normal_probability_between(lo: float,
                               hi: float,
                               mu: float = 0,
                               sigma: float = 1) -> float:
    return normal_cdf(hi, mu, sigma) - normal_cdf(lo, mu, sigma)