Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Evan Miller's Tool - R code
# The code given in #2 gist is not in R. There is a change in formula compared to the one in this blog post and the one used by Evan Miller's tool (#3). http://www.alfredo.motta.name/ab-testing-from-scratch/#easy-footnote-bottom-24-982
#1. https://stats.stackexchange.com/questions/357336/create-an-a-b-sample-size-calculator-using-evan-millers-post
#2. https://gist.github.com/mottalrd/7ddfd45d14bc7433dec2#file-gistfile1-txt
#3. https://www.evanmiller.org/ab-testing/sample-size.html
p = 0.03
pct_mde = 0.1
alpha = 0.05
power = 1- 0.2
delta = p*pct_mde
t_alpha2 = qnorm(1 - alpha/2)
t_beta = qnorm(power)
sd1 =sqrt(2 * p * (1.0 - p))
sd2 =sqrt(p * (1.0 - p) + (p + delta) * (1.0 - p - delta))
n = (t_alpha2 * sd1 + t_beta * sd2) * (t_alpha2 * sd1 + t_beta * sd2) / (delta * delta)
print(n)
#If you set Baseline conversion rate = 3% and minimum detectable effort to be 10% as shown in the example, you get the values on Evan Miller's tool
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment