A/B Testing Reference
Experiment Design Templates
Hypothesis Template
HYPOTHESIS:
If we [specific change],
then [primary metric] will [increase/decrease] by [X%]
because [insight/evidence supporting this belief].
BACKGROUND:
- Current state: [baseline metric value]
- Evidence: [user research, analytics, competitor analysis]
- Confidence: [High/Medium/Low]Test Plan Template
TEST NAME: [Descriptive name]
OWNER: [Name]
STATUS: [Planning/Running/Complete]
HYPOTHESIS:
[Full hypothesis statement]
VARIANTS:
- Control (A): [Current experience]
- Treatment (B): [Changed experience]
- [Treatment (C): Optional additional variant]
METRICS:
- Primary: [Single metric that determines success]
- Secondary: [Supporting metrics]
- Guardrails: [Metrics that must not regress]
AUDIENCE:
- Segment: [Who sees this test]
- Allocation: [% per variant, e.g., 50/50]
- Exclusions: [Who is excluded]
SAMPLE SIZE:
- Required per variant: [N]
- Expected daily traffic: [N]
- Estimated duration: [X weeks]
SUCCESS CRITERIA:
- Minimum detectable effect: [X%]
- Statistical significance: [95%]
- Confidence required: [80% power]
TIMELINE:
- Start date: [Date]
- Minimum runtime: [X weeks]
- Decision date: [Date]Post-Test Analysis Template
TEST: [Name]
DURATION: [Start] to [End]
SAMPLE SIZE: [N control] vs [N treatment]
RESULTS:
| Metric | Control | Treatment | Lift | p-value | Significant? |
|--------|---------|-----------|------|---------|--------------|
| Primary | X% | Y% | +Z% | 0.0X | Yes/No |
| Secondary 1 | | | | | |
| Guardrail 1 | | | | | |
SEGMENT ANALYSIS:
| Segment | Lift | Significant? | Notes |
|---------|------|--------------|-------|
| New users | | | |
| Returning | | | |
| Mobile | | | |
| Desktop | | | |
DECISION: [Ship / Don't Ship / Iterate]
LEARNINGS:
- [Key insight 1]
- [Key insight 2]
NEXT STEPS:
- [Follow-up action]Sample Size Calculator
Quick Reference Table
For 95% confidence, 80% power:
| Baseline Rate | Detect 5% Lift | Detect 10% Lift | Detect 20% Lift |
|---|---|---|---|
| 1% | 3,100,000 | 780,000 | 195,000 |
| 2% | 1,530,000 | 383,000 | 96,000 |
| 5% | 600,000 | 150,000 | 38,000 |
| 10% | 290,000 | 73,000 | 18,500 |
| 20% | 136,000 | 34,000 | 8,600 |
| 30% | 85,000 | 21,500 | 5,400 |
| 50% | 46,000 | 11,600 | 2,900 |
Per variant. Multiply by number of variants.
Formula
n = (2 × (Zα + Zβ)² × p × (1-p)) / (MDE)²
Where:
- Zα = 1.96 (for 95% confidence)
- Zβ = 0.84 (for 80% power)
- p = baseline conversion rate
- MDE = minimum detectable effect (absolute)Duration Calculator
Duration (days) = Sample size per variant × Number of variants / Daily trafficExample:
- Need 10,000 per variant
- 2 variants (A/B)
- 1,000 daily visitors
- Duration = 10,000 × 2 / 1,000 = 20 days
Add buffer for:
- Day-of-week effects (round up to full weeks)
- Novelty effects (add 1 week)
- Holidays/seasonality
Statistical Significance Interpretation
Understanding p-values
| p-value | Interpretation |
|---|---|
| p < 0.01 | Strong evidence against null hypothesis |
| p < 0.05 | Moderate evidence (standard threshold) |
| p < 0.10 | Weak evidence |
| p ≥ 0.10 | Insufficient evidence |
What p-value means: Probability of seeing this result (or more extreme) if there's truly no difference.
What p-value does NOT mean: Probability that the treatment is better.
Confidence Intervals
More useful than p-values for decision-making:
Result: +5% lift, 95% CI: [+2%, +8%]Interpretation:
- Point estimate: 5% improvement
- We're 95% confident true effect is between 2% and 8%
- Entire interval positive = significant win
- Interval includes 0 = not significant
Decision Matrix
| Result | CI includes 0? | Business Impact | Decision |
|---|---|---|---|
| +15% lift | No | Large | Ship immediately |
| +15% lift | Yes | Large | Extend test, get more data |
| +3% lift | No | Small | Ship if low-cost change |
| +3% lift | Yes | Small | Don't ship, not worth it |
| -5% lift | No | Negative | Don't ship, investigate |
| Flat | N/A | None | Don't ship, try bigger change |
Common Statistical Errors
Type I Error (False Positive):
- Concluding effect exists when it doesn't
- Controlled by significance level (α = 0.05 means 5% false positive rate)
Type II Error (False Negative):
- Missing a real effect
- Controlled by power (80% power means 20% false negative rate)
Peeking Problem:
- Checking results before test completes
- Each peek inflates false positive rate
- Solution: Pre-commit to duration, use sequential testing if must peek
SQL Query Templates
Basic A/B Test Results
-- Calculate conversion rate by variant
WITH test_users AS (
SELECT
user_id,
variant,
MIN(exposure_date) as first_exposure
FROM experiment_exposures
WHERE experiment_name = 'your_experiment'
AND exposure_date BETWEEN '2024-01-01' AND '2024-01-14'
GROUP BY user_id, variant
),
conversions AS (
SELECT
user_id,
1 as converted
FROM conversion_events
WHERE event_date BETWEEN '2024-01-01' AND '2024-01-21' -- include conversion window
)
SELECT
t.variant,
COUNT(DISTINCT t.user_id) as users,
COUNT(DISTINCT c.user_id) as conversions,
ROUND(COUNT(DISTINCT c.user_id) * 100.0 / COUNT(DISTINCT t.user_id), 2) as conversion_rate
FROM test_users t
LEFT JOIN conversions c ON t.user_id = c.user_id
GROUP BY t.variant
ORDER BY t.variant;Conversion Rate with Confidence Interval
-- Using normal approximation for CI
WITH metrics AS (
SELECT
variant,
COUNT(*) as n,
SUM(converted) as conversions,
AVG(converted) as rate
FROM experiment_results
GROUP BY variant
)
SELECT
variant,
n,
conversions,
ROUND(rate * 100, 2) as conversion_rate_pct,
ROUND((rate - 1.96 * SQRT(rate * (1-rate) / n)) * 100, 2) as ci_lower,
ROUND((rate + 1.96 * SQRT(rate * (1-rate) / n)) * 100, 2) as ci_upper
FROM metrics;Revenue Per User Analysis
WITH test_users AS (
SELECT
user_id,
variant
FROM experiment_exposures
WHERE experiment_name = 'your_experiment'
),
user_revenue AS (
SELECT
t.user_id,
t.variant,
COALESCE(SUM(o.amount), 0) as revenue
FROM test_users t
LEFT JOIN orders o ON t.user_id = o.user_id
AND o.order_date BETWEEN '2024-01-01' AND '2024-01-31'
GROUP BY t.user_id, t.variant
)
SELECT
variant,
COUNT(*) as users,
SUM(revenue) as total_revenue,
ROUND(AVG(revenue), 2) as avg_revenue_per_user,
ROUND(STDDEV(revenue), 2) as std_dev
FROM user_revenue
GROUP BY variant;Segment Analysis
WITH test_data AS (
SELECT
e.user_id,
e.variant,
u.platform,
u.signup_date,
COALESCE(c.converted, 0) as converted
FROM experiment_exposures e
JOIN users u ON e.user_id = u.user_id
LEFT JOIN conversions c ON e.user_id = c.user_id
WHERE e.experiment_name = 'your_experiment'
)
SELECT
platform,
variant,
COUNT(*) as users,
SUM(converted) as conversions,
ROUND(AVG(converted) * 100, 2) as conversion_rate
FROM test_data
GROUP BY platform, variant
ORDER BY platform, variant;Experimentation Best Practices
Pre-Test Checklist
- Hypothesis documented with expected effect size
- Primary metric defined and measurable
- Guardrail metrics identified
- Sample size calculated
- Duration determined (minimum 1-2 weeks)
- Randomization unit chosen (user, session, device)
- Exclusions defined (employees, bots, etc.)
- QA completed on both variants
- Tracking verified in both variants
During Test
- Monitor for implementation bugs (check variant split)
- Watch guardrail metrics daily
- Don't change anything mid-test
- Don't peek at results (or use sequential testing)
- Document any external events (outages, press, etc.)
Post-Test
- Verify sample size reached
- Check for segment differences
- Calculate practical significance (not just statistical)
- Document learnings regardless of outcome
- Archive results for future reference
Common Pitfalls
1. Stopping Early
- Problem: Peeking at results and stopping when significant
- Impact: Inflates false positive rate dramatically
- Solution: Pre-commit to duration, use sequential testing if must peek
2. Multiple Comparisons
- Problem: Testing many metrics increases false positives
- Impact: 1 in 20 metrics will be "significant" by chance at p<0.05
- Solution: Pre-register primary metric, apply Bonferroni correction for secondary
3. Survivor Bias
- Problem: Only analyzing users who completed certain actions
- Impact: Selection bias, unreliable results
- Solution: Analyze all exposed users, segment separately
4. Novelty/Primacy Effects
- Problem: Users react to newness, not actual improvement
- Impact: Effect fades after launch
- Solution: Run for 2+ weeks, segment new vs. returning users
5. Network Effects
- Problem: Users influence each other (marketplaces, social)
- Impact: Standard analysis invalid
- Solution: Cluster randomization, geo-experiments
6. Underpowered Tests
- Problem: Not enough traffic to detect expected effect
- Impact: High false negative rate
- Solution: Calculate sample size before running, test bigger changes
When NOT to A/B Test
- Change is irreversible (new brand, major pivot)
- Traffic too low (would take 6+ months)
- Change is obvious (fixing bugs, legal requirements)
- Already know it's better (use observational data)
- Cost to build both variants exceeds value of learning