Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Calculating A/B Test Sample Size
"use strict";
//based on https://www.optimizely.com/resources/sample-size-calculator/
function getSampleSize() {
let effect = 0.05; // Minimum Detectable Effect
let significance = 0.95; // Statistical Significance
let conversion = 0.05; // Baseline Conversion Rate
let c = conversion - (conversion * effect);
let p = Math.abs(conversion * effect);
let o = conversion * (1 - conversion) + c * (1 - c);
let n = 2 * significance * o * Math.log(1 + Math.sqrt(o) / p) / (p * p);
return Math.round(n);
}
"use strict";
//based on https://www.qualtrics.com/blog/determining-sample-size/
function getSampleSize() {
let z = 1.96;//z-score for confidence level (95% for 1.95)
let p = 0.5;//standard of deviation (0.5 for 50%/50%)
let e = 0.05;//margin of error
return (z * z) * p * (1 - p) / (e * e);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.