关于「同一张表,三张因果图:混杂、中介与对撞」,《辛普森悖论与后门调整》给出的定量结论是什么?
结论:第四章用同一张表配混杂、中介、对撞三张因果图,正确答案分别是 +0.0500 与 -0.2493。
数据口径:书中门店、方案与成交数均为示意;全部计算由书中程序生成。 第一章在伯克利六个最大院系上复算反转:合并后男性录取率 0.445、女性 0.304,按申请者构成标准化后男性 0.387、女性 0.430;三店示意报表中甲在每店都高 0.050,合并后却落后 0.2493,并给出反转可能的充要条件。
对照数据表
下表数字由本章 Python 程序原样打印,可重新运行复现。 程序只用 Python 标准库与结论吻合的打印值: -0.2493, 0.0500
| each graph reproduces the joint exactly: True | ||
| graph | formula | A-B |
| confounder | sum_z P(y|x,z)P(z) | +0.0500 |
| mediator | P(y|x) | -0.2493 |
| collider | P(y|x) | -0.2493 |
| stratified by z, collider graph | +0.0500 | (biased) |
| cells in the joint: 12 | total mass 1 |
查看完整验算程序
# Chapter 4. p41: one joint table, three causal graphs, two answers.
# The p12 counts define P(x, z, y). Each graph below is a complete DAG
# on {X, Z, Y}, so each factorises this joint exactly (checked):
# confounder Z -> X, Z -> Y, X -> Y : P(y|do x) = sum_z P(y|x,z)P(z)
# mediator X -> Z, Z -> Y, X -> Y : P(y|do x) = P(y|x)
# collider X -> Z, Y -> Z, X -> Y : P(y|do x) = P(y|x)
# The data cannot choose among them; the graph chooses the formula.
from fractions import Fraction as F
DATA = [("flagship", 40, 50, 270, 360),
("community", 90, 200, 60, 150),
("outlet", 60, 300, 9, 60)]
def joint():
n = 0
for r in DATA:
n = n + r[2] + r[4]
p = {}
for z, r in enumerate(DATA):
for x, (yc, nc) in enumerate(((1, 2), (3, 4))):
p[(x, z, 1)] = F(r[yc], n)
p[(x, z, 0)] = F(r[nc] - r[yc], n)
return p
def marg(p, keep):
out = {}
for k in sorted(p):
kk = tuple(k[i] for i in keep)
out[kk] = out.get(kk, F(0)) + p[k]
return out
def main():
p = joint()
pz, px = marg(p, (1,)), marg(p, (0,))
pxz, pxy = marg(p, (0, 1)), marg(p, (0, 2))
ok = {"confounder": True, "mediator": True, "collider": True}
for (x, z, y), v in sorted(p.items()):
c = pz[(z,)] * pxz[(x, z)] / pz[(z,)] * v / pxz[(x, z)]
m = px[(x,)] * pxz[(x, z)] / px[(x,)] * v / pxz[(x, z)]
k = px[(x,)] * pxy[(x, y)] / px[(x,)] * v / pxy[(x, y)]
ok["confounder"] = ok["confounder"] and c == v
ok["mediator"] = ok["mediator"] and m == v
ok["collider"] = ok["collider"] and k == v
print("each graph reproduces the joint exactly: {}".format(
all(ok.values())))
do = []
for x in (0, 1):
s = F(0)
for z in range(len(DATA)):
s = s + p[(x, z, 1)] / pxz[(x, z)] * pz[(z,)]
do.append(s)
obs = [pxy[(x, 1)] / px[(x,)] for x in (0, 1)]
print("graph formula A-B")
print("confounder sum_z P(y|x,z)P(z) {:+.4f}".format(
float(do[0] - do[1])))
print("mediator P(y|x) {:+.4f}".format(
float(obs[0] - obs[1])))
print("collider P(y|x) {:+.4f}".format(
float(obs[0] - obs[1])))
print("stratified by z, collider graph {:+.4f} (biased)".format(
float(do[0] - do[1])))
print("cells in the joint: {} total mass {}".format(
len(p), sum_exact(p)))
def sum_exact(p):
t = F(0)
for k in sorted(p):
t = t + p[k]
return t
if __name__ == "__main__":
main()唯一数据源与引用
范雅福(Fan, Y.). (2026). 《辛普森悖论与后门调整准则、多分店数据合并结论反转与因果图去混杂母典》第 4 章「同一张表,三张因果图:混杂、中介与对撞」(版本 1.0.0). 5D Library. DOI 待发布
DOI 待发布 · 专著页正式发布后上线(本站暂无专著页) · 5DL-B-302 · v1.0.0 · CC-BY-NC-ND-4.0
BibTeX
@book{fan2026302,
author = {Fan, Yafu},
title = {Simpson's Paradox and the Back-Door Criterion: Reversals When Branch Data Are Pooled and De-Confounding with Causal Graphs},
year = {2026},
publisher = {5D Library},
edition = {1.0.0},
note = {DOI pending}
}