示例#1
0
 def beta_on_poisson_sim(t0=25,
                         t1=25,
                         lmb_base=12,
                         alpha=0.05,
                         effect=3,
                         thresh=None,
                         n_sim=10000):
     """
     Obtains the beta (false negative rate) given the observation
     durations for treatment and control and hypothesis test to simulate.
     args:
         t1: VM-duration observed in treatment.
         t2: VM-duration observed in control.
         fn: The test to generate simulated p_value.
             for example: simulate_binned_t_test, simulate_rateratio_test.
     """
     if thresh is None:
         thresh = np.array([alpha])
     po0 = pois.PoissonDist(lmb_base * t0)
     po1 = pois.PoissonDist((lmb_base + effect) * t1)
     tst = lambda n0,n1:binom_test(n1,n0+n1,t1/(t0+t1),\
                 alternative='greater')
     ab = AlphaBetaSim()
     _, _ = ab.alpha_beta_tracer(po0,po1,tst,\
             tst,n_sim=10000)
     beta = ab.beta(alpha)
     return beta
示例#2
0
def same_var_diff_var_t_test(ax,
                             n_prms0=(10, 15, 26),
                             n_prms00=(10, 5, 6),
                             n_prms1=(13, 5, 6)):
    g0 = NormDist(*n_prms0)
    g00 = NormDist(*n_prms00)
    g1 = NormDist(*n_prms1)
    t_tst_obj0 = ttst.TTest_diffvar(alternative='two-sided')
    tst_0 = t_tst_obj0.tst
    t_tst_obj1 = ttst.TTest_equalvar(alternative='two-sided')
    tst_1 = t_tst_obj1.tst
    ab = AlphaBetaSim()
    #alphas1, betas1 = ab.alpha_beta_tracer(g0, g1, tst_0, n_sim=10000)
    #alphas2, betas2 = ab.alpha_beta_tracer(g0, g1, tst_1, n_sim=10000)
    #ax.plot(alphas1, betas1, label="Different variance test")
    #ax.plot(alphas2, betas2, label="Equal variance test")
    alphas1, betas1 = ab.alpha_beta_tracer2(g0, g00, g1, tst_0)
    alphas2, betas2 = ab.alpha_beta_tracer2(g0, g00, g1, tst_1)
    #ax.plot(ab.alpha_hats, alphas1, label="Different variance test")
    #ax.plot(ab.alpha_hats, alphas2, label="Equal variance test")
    ax.plot(alphas1, betas1, label="Different variance test")
    ax.plot(alphas2, betas2, label="Equal variance test")
    #ax.xlabel("Simulated false positive rate")
    #ax.ylabel("Simulated false negative rate")
    ax.legend()
示例#3
0
def tst_simultn():
    #po0=PoissonDist(5)
    #po1=PoissonDist(10)
    po0 = poisson(5); po1 = poisson(10)
    t0=5; t1=10
    ## A hypothesis test that takes the two samples as arguments.
    tst = lambda n0,n1:binom_test(n1,n0+n1,t1/(t0+t1),\
                    alternative='greater')
    ab = AlphaBetaSim()
    alphas,betas=ab.alpha_beta_tracer(po0,po1,tst,tst,n_sim=10000)
    plt.plot(alphas,betas)
    plt.show()
示例#4
0
def beta_plots_poisson_on_poisson():
    t0=10; t1=3
    po0=poisson(2*t0); #po0.random_state = np.random.RandomState(seed=20)
    po1=poisson(3*t1); #po1.random_state = np.random.RandomState(seed=50)
    ## A hypothesis test that takes the two samples as arguments.
    tst_1 = lambda n0,n1:binom_test(n1,n0+n1,t1/(t0+t1),\
                    alternative='greater')
    tst_1_null = lambda n0,n1:binom_test(n1,n0+n1,0.5,\
                    alternative='greater')
    tst_2 = lambda n0,n1:binom_test(n1/3,n0/3+n1/3,t1/(t0+t1),\
                    alternative='greater')
    tst_2_null = lambda n0,n1:binom_test(n1/3,n0/3+n1/3,0.5,\
                    alternative='greater')
    tst_3 = lambda n0,n1:binom_test(n1/.3,n0/.3+n1/.3,t1/(t0+t1),\
                    alternative='greater')
    tst_3_null = lambda n0,n1:binom_test(n1/.3,n0/.3+n1/.3,0.5,\
                    alternative='greater')
    tst_4 = lambda n0,n1:binom_test(n1,n0+n1,t1/(t0+t1),\
                    alternative='two-sided')
    tst_4_null = lambda n0,n1:binom_test(n1,n0+n1,0.5,\
                    alternative='two-sided')
    tst_5 = lambda n0,n1:binom_test(n1/3,n0/3+n1/3,t1/(t0+t1),\
                    alternative='two-sided')
    tst_5_null = lambda n0,n1:binom_test(n1/3,n0/3+n1/3,0.5,\
                    alternative='two-sided')
    tst_6 = lambda n0,n1:binom_test(n1/2,n0/2+n1/2,t1/(t0+t1),\
                    alternative='two-sided')
    tst_6_null = lambda n0,n1:binom_test(n1/2,n0/2+n1/2,0.5,\
                    alternative='two-sided')
    tst_7 = lambda n0,n1:binom_test(n1/.1,n0/.1+n1/.1,t1/(t0+t1),\
                    alternative='two-sided')
    tst_7_null = lambda n0,n1:binom_test(n1/.1,n0/.1+n1/.1,0.5,\
                    alternative='two-sided')
    ab1 = AlphaBetaSim()
    alphas1,betas1=ab1.alpha_beta_tracer(po0,po1,tst_1_null,tst_1,n_sim=10000)
    print("first sim")
    alphas2,betas2=ab1.alpha_beta_tracer(po0,po1,tst_2_null,tst_2,n_sim=10000)
    print("second sim")
    alphas3,betas3=ab1.alpha_beta_tracer(po0,po1,tst_3_null,tst_3,n_sim=10000)
    print("third sim")
    alphas4,betas4=ab1.alpha_beta_tracer(po0,po1,tst_4_null,tst_4,n_sim=10000)
    print("fourth sim")
    alphas5,betas5=ab1.alpha_beta_tracer(po0,po1,tst_5_null,tst_5,n_sim=10000)
    print("fifth sim")
    alphas6,betas6=ab1.alpha_beta_tracer(po0,po1,tst_6_null,tst_6,n_sim=10000)
    print("sixth sim")
    alphas7,betas7=ab1.alpha_beta_tracer(po0,po1,tst_7_null,tst_7,n_sim=10000)
    print("seventh sim")
    plt.plot(alphas1,betas1,label='sc:1_greater')
    plt.plot(alphas2,betas2,label='sc:3_greater')
    plt.plot(alphas3,betas3,label='sc:.3_greater')
    plt.plot(alphas4,betas4,label='sc:1_two_sided')
    plt.plot(alphas5,betas5,label='sc:3_two_sided')
    plt.plot(alphas6,betas6,label='sc:2_two_sided')
    plt.plot(alphas7,betas7,label='sc:.1_two_sided')
    plt.legend()
    plt.show()
示例#5
0
def beta_plots_t_on_gaussian(n0=10,n1=12):
    g0 = NormDist(10,3,n0)
    g1 = NormDist(11,2.5,n1)
    t_tst_obj0 = ttst.TTest(alternative='two-sided')
    tst_0 = t_tst_obj0.tst
    t_tst_obj1 = ttst.TTest(alternative='greater')
    tst_1 = t_tst_obj1.tst
    #
    gaus = ttst.Norm_null()
    t_tst_obj3 = ttst.TTest(alternative='two-sided',dist=gaus)
    tst_2 = t_tst_obj3.tst
    t_tst_obj4 = ttst.TTest(alternative='greater',dist=gaus)
    tst_3 = t_tst_obj4.tst
    ##
    gaus1 = ttst.Norm_null(1,2)
    t_tst_obj4 = ttst.TTest(alternative='two-sided',dist=gaus1)
    tst_4 = t_tst_obj4.tst
    t_tst_obj5 = ttst.TTest(alternative='greater',dist=gaus1)
    tst_5 = t_tst_obj5.tst
    ##
    cauch1 = ttst.Cauchy_null()
    t_tst_obj6 = ttst.TTest(alternative='two-sided',dist=cauch1)
    tst_6 = t_tst_obj6.tst
    t_tst_obj7 = ttst.TTest(alternative='greater',dist=cauch1)
    tst_7 = t_tst_obj7.tst
    ab = AlphaBetaSim()
    #alphas1,betas1=ab.alpha_beta_tracer(g0,g1,tst_0,tst_0,n_sim=10000)
    #print("sim1 done")
    alphas2,betas2=ab.alpha_beta_tracer(g0,g1,tst_1,tst_1,n_sim=10000)
    print("sim2 done")
    #alphas3,betas3=ab.alpha_beta_tracer(g0,g1,tst_2,tst_2,n_sim=10000)
    #print("sim3 done")
    alphas4,betas4=ab.alpha_beta_tracer(g0,g1,tst_3,tst_3,n_sim=10000)
    print("sim4 done")
    #alphas5,betas5=ab.alpha_beta_tracer(g0,g1,tst_4,tst_4,n_sim=10000)
    #print("sim5 done")
    alphas6,betas6=ab.alpha_beta_tracer(g0,g1,tst_5,tst_5,n_sim=10000)
    print("sim6 done")
    #alphas7,betas7=ab.alpha_beta_tracer(g0,g1,tst_6,tst_6,n_sim=10000)
    #print("sim7 done")
    alphas8,betas8=ab.alpha_beta_tracer(g0,g1,tst_7,tst_7,n_sim=10000)
    print("sim8 done")
    #plt.plot(alphas1,betas1,label='t_alternate_2sided')
    plt.plot(alphas2,betas2,label='t_null_distribution')
    #plt.plot(alphas3,betas3,label='normal_alternate_2sided')
    plt.plot(alphas4,betas4,label='standard_normal_null_distribution')
    #plt.plot(alphas5,betas5,label='norm_non_std_alternate_greater')
    plt.plot(alphas6,betas6,label='non_standard_normal_null_distribution')
    #plt.plot(alphas7,betas7,label='norm_non_std_alternate_greater')
    plt.plot(alphas8,betas8,label='cauchy_null_dstribution')
    plt.legend(prop={'size': 20})
    plt.xlabel("False positive rate")
    plt.ylabel("False negative rate")
    plt.show()