故事 · Pearson 给「拟合好坏」发明的尺子 Origin Story · Pearson's Ruler for "Goodness of Fit"
1900 年,统计学家 Karl Pearson 想回答一个反复出现的问题:实际数据和理论预期到底吻合不吻合? 骰子是不是均匀的?孟德尔的豌豆比例对不对?他提出 χ²(卡方)统计量 —— 把每一类的 「观测数 O」和「理论期望数 E」之差平方、再除以 E、最后全加起来。差异越大,χ² 越大。 这把「拟合优度」的尺子后来长出一个更常用的分支:列联表独立性检验 —— 判断两个分类特征(性别与偏好、产线与缺陷类型)是不是有关系。从生物遗传到市场调研、从质量缺陷分析到 A/B 测试, 只要数据是「数格子」,卡方几乎是绕不过去的第一站。 In 1900, statistician Karl Pearson wanted to answer a question that kept showing up: do the actual data really fit the theoretical prediction? Is the die fair? Do Mendel's pea ratios hold? He proposed the χ² (chi-square) statistic — for each category, take the difference between the observed count O and the theoretical expected count E, square it, divide by E, and sum across all categories. The larger the discrepancy, the larger χ². This "goodness-of-fit" ruler later branched into an even more popular use case: the contingency-table test of independence — checking whether two categorical attributes (gender and preference, production line and defect type) are related. From genetics to market research, from defect analysis to A/B testing, whenever the data are "counted in cells," chi-square is almost always the first stop.

1 观测 O 与「若独立则期望 E」并排看 Observed O vs Independence-Expected E, Side by Side

2×2

每格上方是实际观测 O,下方小字是独立假设下的期望 E = 行合计 × 列合计 ÷ 总数。 O 和 E 差得越大,这一格越「红」,对卡方的贡献越多。 The large number in each cell is the observed count O; below it sits the expected count under independence, E = row total × column total ÷ grand total. The bigger the gap between O and E, the redder the cell, and the more it contributes to χ².

2 四格各贡献多少卡方,总和落在哪 How Much Chi-square Each Cell Contributes, and Where the Total Lands

上方四段是每格的 (O−E)²/E 贡献,颜色越深贡献越大;下方数轴把总 χ²临界值 3.84 摆在一起 —— 总值越过红线,就判「行与列不独立」。 The four segments above are each cell's (O−E)²/E contribution — darker means heavier; the axis below places the total χ² next to the critical value 3.84. Cross the red line and the verdict is "rows and columns are not independent."

3 现实里的比例与卡方 Proportions & Chi-square in the Real World

良率检验:这批的合格率是否达到 95% 的目标?单比例 Z 检验直接判达标与否。 Yield check: does this batch meet the 95% pass-rate target? A one-proportion Z-test settles it on the spot.
转化率对比:A/B 两个页面的下单比例差异是否显著,两比例 Z 或 2×2 卡方都能上。 Conversion-rate comparison: is the order-rate gap between page A and page B significant? A two-proportion Z-test or a 2×2 chi-square both fit.
独立性检验:产线与缺陷类型、班次与故障是否相关,列联表卡方一眼看出关联。 Independence testing: is production line related to defect type, or shift related to failure mode? A contingency-table chi-square reveals the link at a glance.
A/B 比例:营销活动响应率、问卷选项分布,分类计数数据的标准武器就是卡方。 A/B proportions: campaign response rates, survey-option distributions — chi-square is the default weapon for categorical count data.
一句话In One Line
卡方的灵魂是一句话:「如果两者真的没关系,数据该长什么样?」 这个「该长的样子」就是期望 E —— 完全由行合计、列合计和总数决定,不掺任何关联。 然后拿真实观测 O 去对照,每格的偏差平方、按 E 缩放(让大格小格公平比较),再全部相加。 偏差全是随机抖动时,χ² 只会在自由度附近的小数徘徊;一旦某些格子系统性地多了或少了,χ² 就被推向右尾。 所以卡方检验从不直接说「有没有关系」,它只回答 「现实离'无关系'这个假设有多远」 —— 远到不像运气能解释,才下结论。比例 Z 检验是它在单格、连续近似下的特例。 The soul of chi-square is one sentence: "If the two truly had nothing to do with each other, what should the data look like?" That "should-look-like" picture is the expected count E — determined entirely by the row totals, column totals, and grand total, with zero association baked in. Then take the actual observed count O, square each cell's gap, scale by E (so a big cell and a small cell can be compared fairly), and sum everything up. When the gaps are just random jitter, χ² merely loiters around small values near its degrees of freedom; once certain cells start systematically overshooting or undershooting, χ² is shoved into the right tail. That is why a chi-square test never answers "is there a relationship?" directly — it only answers "how far is reality from the no-relationship hypothesis?" Far enough that luck can no longer explain it, and only then do we conclude. The proportion Z-test is just its special case for a single cell under the continuous approximation.
常见误用Common Mistakes
期望频数太小还硬用卡方任一格 E < 5 时近似失效,改用 Fisher 精确检验或合并类别。 Forcing chi-square when expected counts are too small. Once any cell has E < 5, the approximation breaks down. Switch to Fisher's exact test or merge categories.
把「显著」当成「强关联」χ² 大也可能只是样本量大;要看 Cramér's V 等效应量衡量关联强度。 Mistaking "significant" for "strong association". A large χ² can simply reflect a large sample. Use an effect-size measure such as Cramér's V to gauge how strong the association actually is.
对配对/重复计数用普通卡方同一对象前后分类的配对数据要用 McNemar 检验,不是独立性卡方。 Running the ordinary chi-square on paired or repeated counts. When the same subjects are classified before and after, use McNemar's test — not the independence chi-square.

比例检验与卡方