Skip to content

Instantly share code, notes, and snippets.

@mottalrd
Last active March 29, 2022 07:38
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mottalrd/7ddfd45d14bc7433dec2 to your computer and use it in GitHub Desktop.
Save mottalrd/7ddfd45d14bc7433dec2 to your computer and use it in GitHub Desktop.
Evan Miller source code for sample size from my blog post http://www.alfredo.motta.name/ab-testing-from-scratch/
function num_subjects(alpha, power_level, p, delta) {
var t_alpha2 = ppnd(1.0-alpha/2);
var t_beta = ppnd(power_level);
var sd1 = Math.sqrt(2 * p * (1.0 - p));
var sd2 = Math.sqrt(p * (1.0 - p) + (p + delta) * (1.0 - p - delta));
return (t_alpha2 * sd1 + t_beta * sd2) * (t_alpha2 * sd1 + t_beta * sd2) / (delta * delta);
}
@mysticaltech
Copy link

This is missing from the part before the declaration of t_alpha2, see https://www.evanmiller.org/ab-testing/sample-size-fixed.js

if (p > 0.5) {
        p = 1.0 - p;
}

@sanjeevpe
Copy link

this is for relative delta. Is there a way to calculate sample size for absolute delta?
thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment