FA-74376 / Experiment statistics / Open access
Conversion rate z-test: Two-sided p-values are halved · case 01
Twice as many experiments are declared significant as the alpha level allows.
ROOT CAUSE
The p-value is 0.5 * erfc(|z|/sqrt 2), a one-tailed probability.
VERIFIED REPAIR
Use erfc(|z| / sqrt 2) for the two-sided p-value.
Unsuccessful approach: Dropping the sqrt 2 scaling evaluates the wrong normal tail.
Case contract
Pooled two-proportion z-test: pool = (conv_a + conv_b) / (n_a + n_b), se = sqrt(pool(1 - pool)(1/n_a + 1/n_b)), z = (p_b - p_a) / se, two-sided p = erfc(|z| / sqrt 2). Nonpositive n -> None; se = 0 -> [0.0, 1.0]. Return [round(z, 6), round(p, 6)].
Why this case matters
Online experiment readouts drive launch decisions; a silent formula slip flips conclusions.
1 / The failure
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(conv_a, n_a, conv_b, n_b):
if n_a <= 0 or n_b <= 0:
return None
pa, pb = conv_a / n_a, conv_b / n_b
pool = (conv_a + conv_b) / (n_a + n_b)
se = math.sqrt(pool * (1 - pool) * (1 / n_a + 1 / n_b))
if se == 0:
return [0.0, 1.0]
z = (pb - pa) / se
p = 0.5 * math.erfc(abs(z) / math.sqrt(2))
return [round(z, 6), round(p, 6)]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('unequal arm sizes weight the pooled rate', [50, 1000, 90, 3000], [-2.98032, 0.002879]),
('treatment better gives positive z', [100, 1000, 130, 1000], [2.102741, 0.035488]),
('treatment worse gives negative z', [130, 1000, 100, 1000], [-2.102741, 0.035488]),
('no conversions anywhere', [0, 500, 0, 500], [0.0, 1.0]),
('all conversions everywhere', [200, 200, 300, 300], [0.0, 1.0]),
('identical rates', [40, 400, 80, 800], [0.0, 1.0]),
('conversion sample 1', [88, 1000, 75, 500], [3.637163, 0.000276]),
('conversion sample 2', [446, 4000, 43, 2500], [-14.022988, 0.0])],
[('treatment better gives positive z', [100, 1000, 130, 1000], [2.102741, 0.035488]),
('treatment worse gives negative z', [130, 1000, 100, 1000], [-2.102741, 0.035488]),
('no conversions anywhere', [0, 500, 0, 500], [0.0, 1.0]),
('all conversions everywhere', [200, 200, 300, 300], [0.0, 1.0]),
('identical rates', [40, 400, 80, 800], [0.0, 1.0]),
('conversion sample 5', [14, 100, 17, 100], [0.586154, 0.557772]),
('conversion sample 6', [455, 4000, 121, 1000], [0.642295, 0.520682]),
('conversion sample 7', [16, 500, 457, 2500], [8.446636, 0.0])],
[('treatment worse gives negative z', [130, 1000, 100, 1000], [-2.102741, 0.035488]),
('no conversions anywhere', [0, 500, 0, 500], [0.0, 1.0]),
('all conversions everywhere', [200, 200, 300, 300], [0.0, 1.0]),
('identical rates', [40, 400, 80, 800], [0.0, 1.0]),
('empty arm', [0, 0, 5, 10], None),
('conversion sample 11', [263, 4000, 78, 1000], [1.374446, 0.169303]),
('conversion sample 14', [558, 4000, 75, 500], [0.636681, 0.524333]),
('conversion sample 16', [200, 1000, 1, 100], [-4.687832, 3e-06])],
[('unequal arm sizes weight the pooled rate', [50, 1000, 90, 3000], [-2.98032, 0.002879]),
('no conversions anywhere', [0, 500, 0, 500], [0.0, 1.0]),
('all conversions everywhere', [200, 200, 300, 300], [0.0, 1.0]),
('identical rates', [40, 400, 80, 800], [0.0, 1.0]),
('empty arm', [0, 0, 5, 10], None),
('conversion sample 16', [200, 1000, 1, 100], [-4.687832, 3e-06]),
('conversion sample 23', [9, 100, 4, 100], [-1.434143, 0.151531]),
('conversion sample 28', [69, 1000, 8, 100], [0.411061, 0.681028])],
[('unequal arm sizes weight the pooled rate', [50, 1000, 90, 3000], [-2.98032, 0.002879]),
('treatment better gives positive z', [100, 1000, 130, 1000], [2.102741, 0.035488]),
('all conversions everywhere', [200, 200, 300, 300], [0.0, 1.0]),
('identical rates', [40, 400, 80, 800], [0.0, 1.0]),
('empty arm', [0, 0, 5, 10], None),
('conversion sample 21', [20, 100, 104, 500], [0.180358, 0.856871]),
('conversion sample 39', [105, 500, 16, 100], [-1.137549, 0.255309]),
('conversion sample 40', [519, 4000, 22, 100], [2.633944, 0.00844])]]
for label, args, expected in fixtures[N - 1]:
check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| unequal arm sizes weight the pooled rate | [-2.98032, 0.00144] | [-2.98032, 0.002879] | Failed |
| treatment better gives positive z | [2.102741, 0.017744] | [2.102741, 0.035488] | Failed |
| treatment worse gives negative z | [-2.102741, 0.017744] | [-2.102741, 0.035488] | Failed |
| no conversions anywhere | [0.0, 1.0] | [0.0, 1.0] | Passed |
| all conversions everywhere | [0.0, 1.0] | [0.0, 1.0] | Passed |
| identical rates | [0.0, 0.5] | [0.0, 1.0] | Failed |
| conversion sample 1 | [3.637163, 0.000138] | [3.637163, 0.000276] | Failed |
| conversion sample 2 | [-14.022988, 0.0] | [-14.022988, 0.0] | Passed |
SHA-256 / 1eaa023eed4573056a7ccdf2529cd56e7f38337163ec4a2b77ff44946c0367d1
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(conv_a, n_a, conv_b, n_b):
if n_a <= 0 or n_b <= 0:
return None
pa, pb = conv_a / n_a, conv_b / n_b
pool = (conv_a + conv_b) / (n_a + n_b)
se = math.sqrt(pool * (1 - pool) * (1 / n_a + 1 / n_b))
if se == 0:
return [0.0, 1.0]
z = (pb - pa) / se
p = math.erfc(abs(z))
return [round(z, 6), round(p, 6)]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('unequal arm sizes weight the pooled rate', [50, 1000, 90, 3000], [-2.98032, 0.002879]),
('treatment better gives positive z', [100, 1000, 130, 1000], [2.102741, 0.035488]),
('treatment worse gives negative z', [130, 1000, 100, 1000], [-2.102741, 0.035488]),
('no conversions anywhere', [0, 500, 0, 500], [0.0, 1.0]),
('all conversions everywhere', [200, 200, 300, 300], [0.0, 1.0]),
('identical rates', [40, 400, 80, 800], [0.0, 1.0]),
('conversion sample 1', [88, 1000, 75, 500], [3.637163, 0.000276]),
('conversion sample 2', [446, 4000, 43, 2500], [-14.022988, 0.0])],
[('treatment better gives positive z', [100, 1000, 130, 1000], [2.102741, 0.035488]),
('treatment worse gives negative z', [130, 1000, 100, 1000], [-2.102741, 0.035488]),
('no conversions anywhere', [0, 500, 0, 500], [0.0, 1.0]),
('all conversions everywhere', [200, 200, 300, 300], [0.0, 1.0]),
('identical rates', [40, 400, 80, 800], [0.0, 1.0]),
('conversion sample 5', [14, 100, 17, 100], [0.586154, 0.557772]),
('conversion sample 6', [455, 4000, 121, 1000], [0.642295, 0.520682]),
('conversion sample 7', [16, 500, 457, 2500], [8.446636, 0.0])],
[('treatment worse gives negative z', [130, 1000, 100, 1000], [-2.102741, 0.035488]),
('no conversions anywhere', [0, 500, 0, 500], [0.0, 1.0]),
('all conversions everywhere', [200, 200, 300, 300], [0.0, 1.0]),
('identical rates', [40, 400, 80, 800], [0.0, 1.0]),
('empty arm', [0, 0, 5, 10], None),
('conversion sample 11', [263, 4000, 78, 1000], [1.374446, 0.169303]),
('conversion sample 14', [558, 4000, 75, 500], [0.636681, 0.524333]),
('conversion sample 16', [200, 1000, 1, 100], [-4.687832, 3e-06])],
[('unequal arm sizes weight the pooled rate', [50, 1000, 90, 3000], [-2.98032, 0.002879]),
('no conversions anywhere', [0, 500, 0, 500], [0.0, 1.0]),
('all conversions everywhere', [200, 200, 300, 300], [0.0, 1.0]),
('identical rates', [40, 400, 80, 800], [0.0, 1.0]),
('empty arm', [0, 0, 5, 10], None),
('conversion sample 16', [200, 1000, 1, 100], [-4.687832, 3e-06]),
('conversion sample 23', [9, 100, 4, 100], [-1.434143, 0.151531]),
('conversion sample 28', [69, 1000, 8, 100], [0.411061, 0.681028])],
[('unequal arm sizes weight the pooled rate', [50, 1000, 90, 3000], [-2.98032, 0.002879]),
('treatment better gives positive z', [100, 1000, 130, 1000], [2.102741, 0.035488]),
('all conversions everywhere', [200, 200, 300, 300], [0.0, 1.0]),
('identical rates', [40, 400, 80, 800], [0.0, 1.0]),
('empty arm', [0, 0, 5, 10], None),
('conversion sample 21', [20, 100, 104, 500], [0.180358, 0.856871]),
('conversion sample 39', [105, 500, 16, 100], [-1.137549, 0.255309]),
('conversion sample 40', [519, 4000, 22, 100], [2.633944, 0.00844])]]
for label, args, expected in fixtures[N - 1]:
check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| unequal arm sizes weight the pooled rate | [-2.98032, 2.5e-05] | [-2.98032, 0.002879] | Failed |
| treatment better gives positive z | [2.102741, 0.002942] | [2.102741, 0.035488] | Failed |
| treatment worse gives negative z | [-2.102741, 0.002942] | [-2.102741, 0.035488] | Failed |
| no conversions anywhere | [0.0, 1.0] | [0.0, 1.0] | Passed |
| all conversions everywhere | [0.0, 1.0] | [0.0, 1.0] | Passed |
| identical rates | [0.0, 1.0] | [0.0, 1.0] | Passed |
| conversion sample 1 | [3.637163, 0.0] | [3.637163, 0.000276] | Failed |
| conversion sample 2 | [-14.022988, 0.0] | [-14.022988, 0.0] | Passed |
SHA-256 / 277d673227ed688bc9003731495ec6b3869cdcc91dbdf764fec5b3daaa5f9f7d
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(conv_a, n_a, conv_b, n_b):
if n_a <= 0 or n_b <= 0:
return None
pa, pb = conv_a / n_a, conv_b / n_b
pool = (conv_a + conv_b) / (n_a + n_b)
se = math.sqrt(pool * (1 - pool) * (1 / n_a + 1 / n_b))
if se == 0:
return [0.0, 1.0]
z = (pb - pa) / se
p = math.erfc(abs(z) / math.sqrt(2))
return [round(z, 6), round(p, 6)]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('unequal arm sizes weight the pooled rate', [50, 1000, 90, 3000], [-2.98032, 0.002879]),
('treatment better gives positive z', [100, 1000, 130, 1000], [2.102741, 0.035488]),
('treatment worse gives negative z', [130, 1000, 100, 1000], [-2.102741, 0.035488]),
('no conversions anywhere', [0, 500, 0, 500], [0.0, 1.0]),
('all conversions everywhere', [200, 200, 300, 300], [0.0, 1.0]),
('identical rates', [40, 400, 80, 800], [0.0, 1.0]),
('conversion sample 1', [88, 1000, 75, 500], [3.637163, 0.000276]),
('conversion sample 2', [446, 4000, 43, 2500], [-14.022988, 0.0])],
[('treatment better gives positive z', [100, 1000, 130, 1000], [2.102741, 0.035488]),
('treatment worse gives negative z', [130, 1000, 100, 1000], [-2.102741, 0.035488]),
('no conversions anywhere', [0, 500, 0, 500], [0.0, 1.0]),
('all conversions everywhere', [200, 200, 300, 300], [0.0, 1.0]),
('identical rates', [40, 400, 80, 800], [0.0, 1.0]),
('conversion sample 5', [14, 100, 17, 100], [0.586154, 0.557772]),
('conversion sample 6', [455, 4000, 121, 1000], [0.642295, 0.520682]),
('conversion sample 7', [16, 500, 457, 2500], [8.446636, 0.0])],
[('treatment worse gives negative z', [130, 1000, 100, 1000], [-2.102741, 0.035488]),
('no conversions anywhere', [0, 500, 0, 500], [0.0, 1.0]),
('all conversions everywhere', [200, 200, 300, 300], [0.0, 1.0]),
('identical rates', [40, 400, 80, 800], [0.0, 1.0]),
('empty arm', [0, 0, 5, 10], None),
('conversion sample 11', [263, 4000, 78, 1000], [1.374446, 0.169303]),
('conversion sample 14', [558, 4000, 75, 500], [0.636681, 0.524333]),
('conversion sample 16', [200, 1000, 1, 100], [-4.687832, 3e-06])],
[('unequal arm sizes weight the pooled rate', [50, 1000, 90, 3000], [-2.98032, 0.002879]),
('no conversions anywhere', [0, 500, 0, 500], [0.0, 1.0]),
('all conversions everywhere', [200, 200, 300, 300], [0.0, 1.0]),
('identical rates', [40, 400, 80, 800], [0.0, 1.0]),
('empty arm', [0, 0, 5, 10], None),
('conversion sample 16', [200, 1000, 1, 100], [-4.687832, 3e-06]),
('conversion sample 23', [9, 100, 4, 100], [-1.434143, 0.151531]),
('conversion sample 28', [69, 1000, 8, 100], [0.411061, 0.681028])],
[('unequal arm sizes weight the pooled rate', [50, 1000, 90, 3000], [-2.98032, 0.002879]),
('treatment better gives positive z', [100, 1000, 130, 1000], [2.102741, 0.035488]),
('all conversions everywhere', [200, 200, 300, 300], [0.0, 1.0]),
('identical rates', [40, 400, 80, 800], [0.0, 1.0]),
('empty arm', [0, 0, 5, 10], None),
('conversion sample 21', [20, 100, 104, 500], [0.180358, 0.856871]),
('conversion sample 39', [105, 500, 16, 100], [-1.137549, 0.255309]),
('conversion sample 40', [519, 4000, 22, 100], [2.633944, 0.00844])]]
for label, args, expected in fixtures[N - 1]:
check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| unequal arm sizes weight the pooled rate | [-2.98032, 0.002879] | [-2.98032, 0.002879] | Passed |
| treatment better gives positive z | [2.102741, 0.035488] | [2.102741, 0.035488] | Passed |
| treatment worse gives negative z | [-2.102741, 0.035488] | [-2.102741, 0.035488] | Passed |
| no conversions anywhere | [0.0, 1.0] | [0.0, 1.0] | Passed |
| all conversions everywhere | [0.0, 1.0] | [0.0, 1.0] | Passed |
| identical rates | [0.0, 1.0] | [0.0, 1.0] | Passed |
| conversion sample 1 | [3.637163, 0.000276] | [3.637163, 0.000276] | Passed |
| conversion sample 2 | [-14.022988, 0.0] | [-14.022988, 0.0] | Passed |
SHA-256 / 3bcb07c8852c88d5cfdf08e98b0750308cc7ba2cfe36e68f2968dd2a177d52e5
Verification & scope
A deterministic toy experiment-analysis model with a stipulated contract; results are rounded and are not a substitute for a validated statistics package. This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.
Observations recorded using Python 3.12.14 at 2026-09-29T14:48:56.280446+00:00.
Case digest / 48010a75ee1d56acb7246fc450adeca760a71ceef245837704057dd0f5a75dbf