A/B Testing in Python
Moe Lotfy, PhD
Principal Data Science Manager
Family-wise Error Rate (FWER): the probability of making one or more type I errors when performing multiple hypothesis tests.
import matplotlib.pyplot as plt
import numpy as np
alpha = 0.05
x = np.linspace(0, 20, 21)
y = 1-(1-alpha)**x
plt.plot(x,y, marker='o')
plt.title('FWER vs Number of Tests')
plt.xlabel('Number of Tests')
plt.ylabel('FWER')
plt.show()
import statsmodels.stats.multitest as smt
pvals = [0.023,0.0005,0.00004]
corrected = smt.multipletests(pvals, alpha=0.05, method='bonferroni')
print("Significant Test:", corrected[0])
print("Corrected P-values:", corrected[1])
print("Bonferroni Corrected alpha: {:.4f}".format(corrected[3]))
Significant Test: [False True True]
Corrected P-values: [0.069 0.0015 0.00012]
Bonferroni Corrected alpha: 0.0167
A/B Testing in Python