Calculates A/B test sample size and duration, writes a reviewable test plan, and analyzes conversion results (z-test, confidence interval, sample ratio check, ship/revert/inconclusive verdict). Use when setting up an A/B test, sizing an experiment, checking whether a test ran long enough, or deciding whether to ship a variant from visitor and conversion counts.
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Ab Test Setup?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/borghei-ab-test-setup)
---
name: ab-test-setup
description: >
Calculates A/B test sample size and duration, writes a reviewable test plan,
and analyzes conversion results (z-test, confidence interval, sample ratio
check, ship/revert/inconclusive verdict). Use when setting up an A/B test,
sizing an experiment, checking whether a test ran long enough, or deciding
whether to ship a variant from visitor and conversion counts.
license: MIT + Commons Clause
metadata:
version: 1.1.0
author: borghei
category: marketing
domain: experimentation
updated: 2026-12-03
tags: [ab-testing, experimentation, statistics, sample-size, conversion-rate]
---
# A/B Test Setup Skill
## Overview
Production-ready A/B testing toolkit for calculating sample sizes, designing rigorous test plans, and analyzing results with statistical significance testing. Designed for growth teams, product managers, and marketers who need to make data-driven decisions from controlled experiments.
## Clarify First
Before designing the test, settle the inputs below. When one is missing or vague and would change the result, ask about it; when it wouldn't, use a sensible default and say which one you used.
- **Hypothesis + primary metric:** what change you expect and the single metric that judges it (drives test plan + analysis).
- **Baseline conversion rate:** the current rate the metric sits at today (drives sample size calculation).
- **Minimum detectable effect (MDE):** smallest lift worth detecting (drives required samples + duration).
- **Daily traffic available:** eligible visitors per day per variant (determines how long the test must run).
Ask about the two or three inputs that matter most for this request, not the whole list. If the user wants a result straight away, produce it and state your assumptions at the top.
## Quick Start
```bash
python3 scripts/sample_size_calculator.py --baseline 0.05 --mde 0.10 --daily-traffic 1000
python3 scripts/test_designer.py assets/sample_config.json
python3 scripts/results_analyzer.py assets/flawed_results.json
```
Real output (excerpt) of the last command:
```
Difference: +0.139 pp (+3.08% relative)
z = 0.511, p = 0.6093 (alpha 0.05), 95% CI [-0.394, +0.672] pp, Cohen's h 0.007
Verdict: INVALID (sample ratio mismatch)
- sample ratio mismatch, p < 0.001 (allocation from input): `control=12500, treatment=11200, expected 11850 / 11850 (chi2 p=3.1e-17)`. Fix: Do not trust this result. Audit assignment, bot filtering and redirects, then re-run
FIX 1 of 1 test(s) need action
```
Every finding quotes the offending input and gives a fix. All tools accept `--format text|json` (`--json` is an alias).
## Exit Codes
| Code | Meaning |
|------|---------|
| 0 | `sample_size_calculator`: plan fits `--max-days` (or no traffic given). `test_designer`: no gaps. `results_analyzer`: every test is a significant win with a healthy split |
| 1 | Findings to act on: plan too long, config gaps, loss, inconclusive result, sample ratio mismatch, thin data |
| 2 | Unusable input (bad flag value, empty or non-JSON file, missing field, conversions greater than visitors). One `BLOCKED:` line, no traceback |
## Tools Overview
| Tool | Purpose | Input |
|------|---------|-------|
| `sample_size_calculator.py` | Visitors per arm and days needed | `--baseline`, `--mde` (relative lift), optional `--daily-traffic`, `--variants`, `--max-days` |
| `test_designer.py` | Test plan with decision rule, timeline, checklist | JSON config (required fields below) |
| `results_analyzer.py` | Z-test, CI, Cohen's h, sample ratio mismatch check, verdict | JSON counts; `--batch` for many tests; `--bayesian` adds a seeded Beta-Binomial comparison |
| `abstats.py` | Shared helper module (not a command) | |
Notes on behaviour: with more than 2 variants the sample size uses a Bonferroni alpha (alpha / (variants - 1)). The 14-day floor, 30-day and 56-day length limits, 3-secondary-metric limit and the 1% low-baseline flag are internal heuristics, labelled as such in the output. The sample-ratio alarm (p < 0.001) is a common platform convention. `test_designer` never invents defaults: missing required fields exit 2, and a missing `daily_traffic`, hypothesis or guardrail list is reported as a gap.
## Workflows
### Workflow 1: New A/B Test Setup
1. Define the hypothesis and the single primary metric.
2. `python3 scripts/sample_size_calculator.py --baseline <rate> --mde <lift> --daily-traffic <n>`; if it exits 1, apply the suggested MDE or add traffic.
3. Write the config (see below; `assets/sample_config.json`) and run `python3 scripts/test_designer.py <config>`; close every gap until it prints PASS.
4. Share the plan before launch; check the visitor split after day 1.
### Workflow 2: Test Results Analysis
1. Put counts in JSON (`assets/sample_results.json`); include `allocation` so the split check uses your real design.
2. `python3 scripts/results_analyzer.py <file> --bayesian`
3. Act on the verdict: SHIP, REVERT, INCONCLUSIVE (the fix states the lift your sample could detect) or INVALID (fix assignment first).
### Workflow 3: Program Review
`python3 scripts/results_analyzer.py assets/sample_batch.json --batch` reports ship / revert / inconclusive / invalid counts across tests.
## Reference Documentation
`references/ab-testing-guide.md`: statistical foundations, sample size theory, pitfalls, sequential and Bayesian approaches.
## Config and Results Formats
Config (`test_designer.py`; required: `test_name`, `hypothesis`, `metric_primary`, `baseline_rate`, `minimum_detectable_effect`, `variants`; `daily_traffic` means eligible visitors per day, all arms combined):
```json
{"test_name": "Homepage CTA colour", "hypothesis": "... will increase cta_click_rate because ...",
"metric_primary": "cta_click_rate", "baseline_rate": 0.045, "minimum_detectable_effect": 0.15,
"daily_traffic": 5000, "variants": [{"name": "control", "description": "Blue"}, {"name": "treatment", "description": "Green"}],
"guardrail_metrics": [{"metric": "bounce_rate", "threshold": "no more than +5% relative"}]}
```
Results (`results_analyzer.py`; exactly two arms named `control` and `treatment`, or a list of two):
```json
{"test_name": "Homepage CTA colour", "allocation": {"control": 0.5, "treatment": 0.5},
"variants": {"control": {"visitors": 12500, "conversions": 563}, "treatment": {"visitors": 12480, "conversions": 702}}}
```
## Scope & Limitations
**In Scope:**
- Sample size and duration estimates for conversion-rate tests with `sample_size_calculator.py`, using the two-proportion z-test formula with configurable alpha, power, one- or two-sided testing, allocation and variant count
- Test plan generation from a JSON config (hypothesis, primary and secondary metrics, variants, traffic split) with `test_designer.py`
- Results analysis with `results_analyzer.py`: two-proportion z-test, p-value, confidence interval and Cohen's h effect size, with optional Bayesian analysis and batch mode for reviewing several tests
- A methodology guide covering statistical foundations, common pitfalls such as peeking and multiple comparisons, and sequential and Bayesian approaches
**Out of Scope:**
- Running the experiment, assigning traffic or serving variants; the skill does not connect to any testing platform
- Event tracking and instrumentation that produces the visitor and conversion counts (see `marketing/analytics-tracking/`)
- Continuous metrics such as revenue per user, regression and other statistical methods beyond proportion tests (see `data-analytics/statistical-analyst/`)
- Deciding what to test on a page or form (see `business-growth/page-cro/` and `business-growth/form-cro/`)
**Important Caveats:**
- The tools model binary conversion metrics only. Visitor and conversion counts are entered by hand in JSON. `examples/test_results.csv` is a raw-log example only; the tools do not read CSV.
- `results_analyzer.py` compares two variants (control and treatment). It exits 2 for A/B/n input; analyze arms pairwise in separate files. `sample_size_calculator.py` applies a Bonferroni alpha for more than 2 variants.
- `results_analyzer.py` checks sample ratio mismatch; segment effects, novelty effects and peeking are not checked (see the reference guide).