Customer Analytics and A/B Testing in Python
Ryan Grossman
Data Scientist, EDO
Statistical Power: Probability of finding a statistically significant result when the Null Hypothesis is false
# Calculate the test power (some details omitted) def get_power(n, p1, p2, cl): alpha = 1 - cl qu = stats.norm.ppf(1 - alpha/2) diff = abs(p2 - p1) bp = (p1 + p2) / 2 ... power = power_part_one + power_part_two return(power)
# Calculate the sample size needed for the specified # power and confidence level def get_sample_size(power, p1, p2, cl, max_n = 1000000): n = 1 while n <= max_n: tmp_power = get_power(n, p1, p2, cl) if tmp_power >= power: return n else: n = n + 1
sample_size_per_group = get_sample_size(
0.8 # Desired Power
conversion_rate,
conversion_rate * 1.1 # Lifted conversion rate,
0.95 # Confidence level)
print(sample_size_per_group)
45788
Customer Analytics and A/B Testing in Python