FA-74706 / Experiment statistics / Open access
Cluster randomisation design effect: Unequal cluster sizes are ignored · case 01
Design effects are understated when a few accounts are much larger than the rest.
ROOT CAUSE
The inflation term uses (m - 1) without the cv^2 adjustment.
VERIFIED REPAIR
Use ((cv^2 + 1) m - 1) in the design effect.
Unsuccessful approach: Dropping the +1 inside the factor removes the base cluster-size term.
Case contract
For clusters (e.g. companies) randomised as units: mean size m, population variance of sizes / m^2 = cv^2, design effect = 1 + ((cv^2 + 1) m - 1) icc. Effective sample = total units / design effect; clusters needed = ceil(n_required * design effect / m). No clusters or zero mean -> None. Return [round(deff, 6), round(effective n, 6), clusters needed].
Why this case matters
B2B experiments randomise by account; ignoring clustering makes results look far more certain.
1 / The failure
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(cluster_sizes, icc, n_required):
k = len(cluster_sizes)
if k == 0:
return None
total = sum(cluster_sizes)
mbar = total / k
if mbar == 0:
return None
var = sum((s - mbar) ** 2 for s in cluster_sizes) / k
cv2 = var / mbar ** 2
deff = 1 + (mbar - 1) * icc
return [round(deff, 6), round(total / deff, 6), math.ceil(n_required * deff / mbar)]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('unequal cluster sizes inflate the design effect', [[5, 10, 20, 45], 0.05, 500], [2.54375, 31.449631, 64]),
('equal clusters', [[10, 10, 10], 0.1, 300], [1.9, 15.789474, 57]),
('zero icc means no inflation', [[3, 40], 0.0, 100], [1.0, 43.0, 5]),
('single cluster', [[25], 0.2, 100], [5.8, 4.310345, 24]),
('small clusters', [[2, 4], 0.3, 50], [1.7, 3.529412, 29]),
('cluster sample 1', [[40, 20, 40, 20, 20, 40], 0.01, 500], [1.323333, 136.020151, 23]),
('cluster sample 2', [[3, 10, 10, 20], 0.05, 1000], [1.65814, 25.932679, 155]),
('cluster sample 3', [[40, 10, 5], 0.01, 500], [1.303636, 42.189679, 36])],
[('unequal cluster sizes inflate the design effect', [[5, 10, 20, 45], 0.05, 500], [2.54375, 31.449631, 64]),
('equal clusters', [[10, 10, 10], 0.1, 300], [1.9, 15.789474, 57]),
('zero icc means no inflation', [[3, 40], 0.0, 100], [1.0, 43.0, 5]),
('single cluster', [[25], 0.2, 100], [5.8, 4.310345, 24]),
('small clusters', [[2, 4], 0.3, 50], [1.7, 3.529412, 29]),
('cluster sample 4', [[20, 10, 20, 5, 5, 3], 0.2, 100], [3.844444, 16.387283, 37]),
('cluster sample 6', [[40], 0.2, 1000], [8.8, 4.545455, 220]),
('cluster sample 8', [[5, 5, 3, 5], 0.2, 1000], [1.733333, 10.384615, 386])],
[('unequal cluster sizes inflate the design effect', [[5, 10, 20, 45], 0.05, 500], [2.54375, 31.449631, 64]),
('equal clusters', [[10, 10, 10], 0.1, 300], [1.9, 15.789474, 57]),
('zero icc means no inflation', [[3, 40], 0.0, 100], [1.0, 43.0, 5]),
('single cluster', [[25], 0.2, 100], [5.8, 4.310345, 24]),
('small clusters', [[2, 4], 0.3, 50], [1.7, 3.529412, 29]),
('cluster sample 11', [[40], 0.01, 500], [1.39, 28.776978, 18]),
('cluster sample 17', [[20, 40, 3, 20, 5], 0.05, 100], [2.332955, 37.720409, 14]),
('cluster sample 24', [[5, 10], 0.2, 100], [2.466667, 6.081081, 33])],
[('unequal cluster sizes inflate the design effect', [[5, 10, 20, 45], 0.05, 500], [2.54375, 31.449631, 64]),
('equal clusters', [[10, 10, 10], 0.1, 300], [1.9, 15.789474, 57]),
('zero icc means no inflation', [[3, 40], 0.0, 100], [1.0, 43.0, 5]),
('single cluster', [[25], 0.2, 100], [5.8, 4.310345, 24]),
('small clusters', [[2, 4], 0.3, 50], [1.7, 3.529412, 29]),
('cluster sample 16', [[3, 20, 10, 5, 10, 40], 0.0, 500], [1.0, 88.0, 35]),
('cluster sample 25', [[10, 5, 3, 40], 0.05, 100], [2.444828, 23.723554, 17]),
('cluster sample 39', [[5, 10], 0.01, 500], [1.073333, 13.975155, 72])],
[('unequal cluster sizes inflate the design effect', [[5, 10, 20, 45], 0.05, 500], [2.54375, 31.449631, 64]),
('equal clusters', [[10, 10, 10], 0.1, 300], [1.9, 15.789474, 57]),
('zero icc means no inflation', [[3, 40], 0.0, 100], [1.0, 43.0, 5]),
('single cluster', [[25], 0.2, 100], [5.8, 4.310345, 24]),
('small clusters', [[2, 4], 0.3, 50], [1.7, 3.529412, 29]),
('cluster sample 21', [[40, 10, 5], 0.05, 100], [2.518182, 21.841155, 14]),
('cluster sample 36', [[5, 10, 20, 3], 0.01, 1000], [1.130526, 33.612663, 120]),
('cluster sample 49', [[20, 10, 20, 20, 10, 3], 0.01, 1000], [1.159759, 71.56659, 84])]]
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 cluster sizes inflate the design effect | [1.95, 41.025641, 49] | [2.54375, 31.449631, 64] | Failed |
| equal clusters | [1.9, 15.789474, 57] | [1.9, 15.789474, 57] | Passed |
| zero icc means no inflation | [1.0, 43.0, 5] | [1.0, 43.0, 5] | Passed |
| single cluster | [5.8, 4.310345, 24] | [5.8, 4.310345, 24] | Passed |
| small clusters | [1.6, 3.75, 27] | [1.7, 3.529412, 29] | Failed |
| cluster sample 1 | [1.29, 139.534884, 22] | [1.323333, 136.020151, 23] | Failed |
| cluster sample 2 | [1.4875, 28.907563, 139] | [1.65814, 25.932679, 155] | Failed |
| cluster sample 3 | [1.173333, 46.875, 32] | [1.303636, 42.189679, 36] | Failed |
SHA-256 / f47f45bff178e4d0c0c7de87eca77a1fa753e6b6484d01698e2f348b9771cefa
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(cluster_sizes, icc, n_required):
k = len(cluster_sizes)
if k == 0:
return None
total = sum(cluster_sizes)
mbar = total / k
if mbar == 0:
return None
var = sum((s - mbar) ** 2 for s in cluster_sizes) / k
cv2 = var / mbar ** 2
deff = 1 + (cv2 * mbar - 1) * icc
return [round(deff, 6), round(total / deff, 6), math.ceil(n_required * deff / mbar)]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('unequal cluster sizes inflate the design effect', [[5, 10, 20, 45], 0.05, 500], [2.54375, 31.449631, 64]),
('equal clusters', [[10, 10, 10], 0.1, 300], [1.9, 15.789474, 57]),
('zero icc means no inflation', [[3, 40], 0.0, 100], [1.0, 43.0, 5]),
('single cluster', [[25], 0.2, 100], [5.8, 4.310345, 24]),
('small clusters', [[2, 4], 0.3, 50], [1.7, 3.529412, 29]),
('cluster sample 1', [[40, 20, 40, 20, 20, 40], 0.01, 500], [1.323333, 136.020151, 23]),
('cluster sample 2', [[3, 10, 10, 20], 0.05, 1000], [1.65814, 25.932679, 155]),
('cluster sample 3', [[40, 10, 5], 0.01, 500], [1.303636, 42.189679, 36])],
[('unequal cluster sizes inflate the design effect', [[5, 10, 20, 45], 0.05, 500], [2.54375, 31.449631, 64]),
('equal clusters', [[10, 10, 10], 0.1, 300], [1.9, 15.789474, 57]),
('zero icc means no inflation', [[3, 40], 0.0, 100], [1.0, 43.0, 5]),
('single cluster', [[25], 0.2, 100], [5.8, 4.310345, 24]),
('small clusters', [[2, 4], 0.3, 50], [1.7, 3.529412, 29]),
('cluster sample 4', [[20, 10, 20, 5, 5, 3], 0.2, 100], [3.844444, 16.387283, 37]),
('cluster sample 6', [[40], 0.2, 1000], [8.8, 4.545455, 220]),
('cluster sample 8', [[5, 5, 3, 5], 0.2, 1000], [1.733333, 10.384615, 386])],
[('unequal cluster sizes inflate the design effect', [[5, 10, 20, 45], 0.05, 500], [2.54375, 31.449631, 64]),
('equal clusters', [[10, 10, 10], 0.1, 300], [1.9, 15.789474, 57]),
('zero icc means no inflation', [[3, 40], 0.0, 100], [1.0, 43.0, 5]),
('single cluster', [[25], 0.2, 100], [5.8, 4.310345, 24]),
('small clusters', [[2, 4], 0.3, 50], [1.7, 3.529412, 29]),
('cluster sample 11', [[40], 0.01, 500], [1.39, 28.776978, 18]),
('cluster sample 17', [[20, 40, 3, 20, 5], 0.05, 100], [2.332955, 37.720409, 14]),
('cluster sample 24', [[5, 10], 0.2, 100], [2.466667, 6.081081, 33])],
[('unequal cluster sizes inflate the design effect', [[5, 10, 20, 45], 0.05, 500], [2.54375, 31.449631, 64]),
('equal clusters', [[10, 10, 10], 0.1, 300], [1.9, 15.789474, 57]),
('zero icc means no inflation', [[3, 40], 0.0, 100], [1.0, 43.0, 5]),
('single cluster', [[25], 0.2, 100], [5.8, 4.310345, 24]),
('small clusters', [[2, 4], 0.3, 50], [1.7, 3.529412, 29]),
('cluster sample 16', [[3, 20, 10, 5, 10, 40], 0.0, 500], [1.0, 88.0, 35]),
('cluster sample 25', [[10, 5, 3, 40], 0.05, 100], [2.444828, 23.723554, 17]),
('cluster sample 39', [[5, 10], 0.01, 500], [1.073333, 13.975155, 72])],
[('unequal cluster sizes inflate the design effect', [[5, 10, 20, 45], 0.05, 500], [2.54375, 31.449631, 64]),
('equal clusters', [[10, 10, 10], 0.1, 300], [1.9, 15.789474, 57]),
('zero icc means no inflation', [[3, 40], 0.0, 100], [1.0, 43.0, 5]),
('single cluster', [[25], 0.2, 100], [5.8, 4.310345, 24]),
('small clusters', [[2, 4], 0.3, 50], [1.7, 3.529412, 29]),
('cluster sample 21', [[40, 10, 5], 0.05, 100], [2.518182, 21.841155, 14]),
('cluster sample 36', [[5, 10, 20, 3], 0.01, 1000], [1.130526, 33.612663, 120]),
('cluster sample 49', [[20, 10, 20, 20, 10, 3], 0.01, 1000], [1.159759, 71.56659, 84])]]
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 cluster sizes inflate the design effect | [1.54375, 51.821862, 39] | [2.54375, 31.449631, 64] | Failed |
| equal clusters | [0.9, 33.333333, 27] | [1.9, 15.789474, 57] | Failed |
| zero icc means no inflation | [1.0, 43.0, 5] | [1.0, 43.0, 5] | Passed |
| single cluster | [0.8, 31.25, 4] | [5.8, 4.310345, 24] | Failed |
| small clusters | [0.8, 7.5, 14] | [1.7, 3.529412, 29] | Failed |
| cluster sample 1 | [1.023333, 175.895765, 18] | [1.323333, 136.020151, 23] | Failed |
| cluster sample 2 | [1.12064, 38.370947, 105] | [1.65814, 25.932679, 155] | Failed |
| cluster sample 3 | [1.120303, 49.09386, 31] | [1.303636, 42.189679, 36] | Failed |
SHA-256 / d96058dbb1f654632797ec6a9c9d89e76bcbc07e0a863a6b63e6ce63eb1f30b3
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(cluster_sizes, icc, n_required):
k = len(cluster_sizes)
if k == 0:
return None
total = sum(cluster_sizes)
mbar = total / k
if mbar == 0:
return None
var = sum((s - mbar) ** 2 for s in cluster_sizes) / k
cv2 = var / mbar ** 2
deff = 1 + ((cv2 + 1) * mbar - 1) * icc
return [round(deff, 6), round(total / deff, 6), math.ceil(n_required * deff / mbar)]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('unequal cluster sizes inflate the design effect', [[5, 10, 20, 45], 0.05, 500], [2.54375, 31.449631, 64]),
('equal clusters', [[10, 10, 10], 0.1, 300], [1.9, 15.789474, 57]),
('zero icc means no inflation', [[3, 40], 0.0, 100], [1.0, 43.0, 5]),
('single cluster', [[25], 0.2, 100], [5.8, 4.310345, 24]),
('small clusters', [[2, 4], 0.3, 50], [1.7, 3.529412, 29]),
('cluster sample 1', [[40, 20, 40, 20, 20, 40], 0.01, 500], [1.323333, 136.020151, 23]),
('cluster sample 2', [[3, 10, 10, 20], 0.05, 1000], [1.65814, 25.932679, 155]),
('cluster sample 3', [[40, 10, 5], 0.01, 500], [1.303636, 42.189679, 36])],
[('unequal cluster sizes inflate the design effect', [[5, 10, 20, 45], 0.05, 500], [2.54375, 31.449631, 64]),
('equal clusters', [[10, 10, 10], 0.1, 300], [1.9, 15.789474, 57]),
('zero icc means no inflation', [[3, 40], 0.0, 100], [1.0, 43.0, 5]),
('single cluster', [[25], 0.2, 100], [5.8, 4.310345, 24]),
('small clusters', [[2, 4], 0.3, 50], [1.7, 3.529412, 29]),
('cluster sample 4', [[20, 10, 20, 5, 5, 3], 0.2, 100], [3.844444, 16.387283, 37]),
('cluster sample 6', [[40], 0.2, 1000], [8.8, 4.545455, 220]),
('cluster sample 8', [[5, 5, 3, 5], 0.2, 1000], [1.733333, 10.384615, 386])],
[('unequal cluster sizes inflate the design effect', [[5, 10, 20, 45], 0.05, 500], [2.54375, 31.449631, 64]),
('equal clusters', [[10, 10, 10], 0.1, 300], [1.9, 15.789474, 57]),
('zero icc means no inflation', [[3, 40], 0.0, 100], [1.0, 43.0, 5]),
('single cluster', [[25], 0.2, 100], [5.8, 4.310345, 24]),
('small clusters', [[2, 4], 0.3, 50], [1.7, 3.529412, 29]),
('cluster sample 11', [[40], 0.01, 500], [1.39, 28.776978, 18]),
('cluster sample 17', [[20, 40, 3, 20, 5], 0.05, 100], [2.332955, 37.720409, 14]),
('cluster sample 24', [[5, 10], 0.2, 100], [2.466667, 6.081081, 33])],
[('unequal cluster sizes inflate the design effect', [[5, 10, 20, 45], 0.05, 500], [2.54375, 31.449631, 64]),
('equal clusters', [[10, 10, 10], 0.1, 300], [1.9, 15.789474, 57]),
('zero icc means no inflation', [[3, 40], 0.0, 100], [1.0, 43.0, 5]),
('single cluster', [[25], 0.2, 100], [5.8, 4.310345, 24]),
('small clusters', [[2, 4], 0.3, 50], [1.7, 3.529412, 29]),
('cluster sample 16', [[3, 20, 10, 5, 10, 40], 0.0, 500], [1.0, 88.0, 35]),
('cluster sample 25', [[10, 5, 3, 40], 0.05, 100], [2.444828, 23.723554, 17]),
('cluster sample 39', [[5, 10], 0.01, 500], [1.073333, 13.975155, 72])],
[('unequal cluster sizes inflate the design effect', [[5, 10, 20, 45], 0.05, 500], [2.54375, 31.449631, 64]),
('equal clusters', [[10, 10, 10], 0.1, 300], [1.9, 15.789474, 57]),
('zero icc means no inflation', [[3, 40], 0.0, 100], [1.0, 43.0, 5]),
('single cluster', [[25], 0.2, 100], [5.8, 4.310345, 24]),
('small clusters', [[2, 4], 0.3, 50], [1.7, 3.529412, 29]),
('cluster sample 21', [[40, 10, 5], 0.05, 100], [2.518182, 21.841155, 14]),
('cluster sample 36', [[5, 10, 20, 3], 0.01, 1000], [1.130526, 33.612663, 120]),
('cluster sample 49', [[20, 10, 20, 20, 10, 3], 0.01, 1000], [1.159759, 71.56659, 84])]]
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 cluster sizes inflate the design effect | [2.54375, 31.449631, 64] | [2.54375, 31.449631, 64] | Passed |
| equal clusters | [1.9, 15.789474, 57] | [1.9, 15.789474, 57] | Passed |
| zero icc means no inflation | [1.0, 43.0, 5] | [1.0, 43.0, 5] | Passed |
| single cluster | [5.8, 4.310345, 24] | [5.8, 4.310345, 24] | Passed |
| small clusters | [1.7, 3.529412, 29] | [1.7, 3.529412, 29] | Passed |
| cluster sample 1 | [1.323333, 136.020151, 23] | [1.323333, 136.020151, 23] | Passed |
| cluster sample 2 | [1.65814, 25.932679, 155] | [1.65814, 25.932679, 155] | Passed |
| cluster sample 3 | [1.303636, 42.189679, 36] | [1.303636, 42.189679, 36] | Passed |
SHA-256 / 7b5f01192f8ca3690f2115124faf5505f3beb84aad664664d3b16b259862a43d
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:59.200167+00:00.
Case digest / 187ead93ed7461822e4df029c31782070345db58ea1ec7e87dbc9e93befb623b