Created
February 16, 2021 02:01
-
-
Save ryu577/ed535a6457dc98672c39cfe47f1894b6 to your computer and use it in GitHub Desktop.
False positive rate to false negative rate profile for Welch and two sample t-tests when different normally distributed data is passed to them.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
from scipy.stats import poisson, norm, t | |
from hypothtst.alpha_beta_sim import AlphaBetaSim | |
from hypothtst.sim_utils.mean.normal import NormDist | |
# pip install hypothtst to get this library. | |
def same_var_diff_var_t_test(ax, n_prms0=(10, 15, 26), n_prms1=(13, 5, 6)): | |
g0 = NormDist(*n_prms0) | |
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") | |
ax.legend() | |
def plot_grid(): | |
ns = np.array([0.3, 1.0, 5.0]) | |
sigs = np.array([0.3, 1.0, 3.0]) | |
fig, axs = plt.subplots(len(ns),len(sigs)) | |
i=-1 | |
for n_ratio in ns: | |
i+=1 | |
n1 = int(30) | |
n2 = int(n1*n_ratio) | |
j=-1 | |
for sig_ratio in sigs: | |
j+=1 | |
sig1 = 10 | |
sig2 = sig1*sig_ratio | |
prms0 = (10, sig1, n1) | |
prms1 = (13, sig2, n2) | |
ax = axs[i,j] | |
ax.set_title('n1='+str(n1)+' n2=' + str(n2)+' sig1='+str(sig1)+' sig2='+str(sig2)) | |
same_var_diff_var_t_test(ax, prms0, prms1) | |
print("Plotted: " + str((i,j))) | |
plt.show() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment