# 双样本比例 z 检验

双样本比例 z 检验是一种统计假设检验，用于比较两个独立样本中二分类结果的比例，即判断观察到的差异是否大于随机变异所能预测的范围。它是 2×2 比较中标准的大样本检验之一，适用于临床试验、A/B 实验、调查和质量控制中两个组各用一个成功率来概括的情形。

| 关键事实 | 详情 |
|---|---|
| 原假设 | 两个总体比例相等，\( H_0: p_1 - p_2 = 0 \)；备择假设可以是双侧或单侧<sup>[1](https://www.socscistatistics.com/tutorials/z-test-two-proportions/)</sup><sup> • </sup><sup>[2](https://www.statsmodels.org/stable/generated/statsmodels.stats.proportion.proportions_ztest.html)</sup> |
| 检验统计量 | \( z = (\hat{p}_1 - \hat{p}_2) / \sqrt{\hat{p}_{pool}(1-\hat{p}_{pool})(1/n_1 + 1/n_2)} \)，使用原假设下的合并比例<sup>[3](https://mtstateintrostats.github.io/IntroStatTextbook/inference-two-props.html)</sup> |
| 合并比例 | \( \hat{p}_{pool} = (x_1 + x_2)/(n_1 + n_2) \)，即两个样本合计的成功率<sup>[1](https://www.socscistatistics.com/tutorials/z-test-two-proportions/)</sup> |
| 条件 | 独立样本以及成功-失败条件，合并后的期望计数均至少为 10（常见的较宽松规则是 \( n_i p_i > 5 \)）<sup>[3](https://mtstateintrostats.github.io/IntroStatTextbook/inference-two-props.html)</sup><sup> • </sup><sup>[4](https://pmc.ncbi.nlm.nih.gov/articles/PMC4868880/)</sup> |
| 决策规则 | 当双侧 \( |z| \) 超过约 1.96 时，或在 p 值低于 \( \alpha \) 时，在显著性水平 \( \alpha \) 下拒绝原假设；常用水平为 0.10、0.05 和 0.01<sup>[5](https://www.statology.org/two-proportion-z-test/)</sup> |
| 与卡方检验的关系 | 在双侧备择假设下，该检验给出的 p 值与 2×2 表上的皮尔逊卡方检验相同，因为 \( z^2 \) 服从自由度为 1 的卡方分布<sup>[2](https://www.statsmodels.org/stable/generated/statsmodels.stats.proportion.proportions_ztest.html)</sup> |
| 软件 | Python 的 statsmodels 中提供为 `proportions_ztest`，R 中提供为 `prop.test`，后者带有可选的耶茨连续性校正<sup>[2](https://www.statsmodels.org/stable/generated/statsmodels.stats.proportion.proportions_ztest.html)</sup><sup> • </sup><sup>[6](https://www.rdocumentation.org/packages/stats/versions/3.3.2/topics/prop.test)</sup> |

## 目的与典型用途

该检验回答一个具体问题：给定两个独立组和一个二分类结果，观察到的比例差异是否大到不能归因于偶然？临床试验可能比较用药组与安慰剂组之间的康复率；网络团队可能比较改版前后的转化率；公共卫生分析师可能比较两个地区的疫苗接种覆盖率。<sup>[1](https://www.socscistatistics.com/tutorials/z-test-two-proportions/)</sup> 在每种情况下，数据都归结为四个计数：两个组各自的成功数和失败数。

该检验要求两个样本相互独立。

## 检验的工作原理

该检验从两个总体比例相等的原假设出发。在这一假定下，两个样本估计的是同一个潜在比例，因此对它的自然估计是合并比例，即两组中成功总数除以观察总数。在一项试验中，200 名用药患者中有 140 人康复，200 名安慰剂患者中有 110 人康复，合并比例为 \( (140 + 110)/(200 + 200) = 0.625 \)。<sup>[1](https://www.socscistatistics.com/tutorials/z-test-two-proportions/)</sup>

然后，用这个合并值代入两个总体比例，估计差值 \( \hat{p}_1 - \hat{p}_2 \) 的标准误：<sup>[3](https://mtstateintrostats.github.io/IntroStatTextbook/inference-two-props.html)</sup>

\[ SE_0 = \sqrt{\hat{p}_{pool}(1-\hat{p}_{pool})\left(\frac{1}{n_1} + \frac{1}{n_2}\right)} \]

检验统计量是观察到的差值除以此原假设标准误。它衡量观察到的差值距离零有多少个标准误——零是原假设为真时的期望值。接近零的值与比例相等一致；落在约 −1.96 至 1.96 的范围之外的值对应于低于 0.05 的双侧 p 值。<sup>[1](https://www.socscistatistics.com/tutorials/z-test-two-proportions/)</sup>

**为什么检验使用合并比例而区间不使用。** 在检验 \( H_0: p_1 = p_2 \) 时，原假设本身断言存在一个共同的单一比例，因此合并估计是方差计算的最佳可用值，所得的统计量是该假设的得分检验。<sup>[3](https://mtstateintrostats.github.io/IntroStatTextbook/inference-two-props.html)</sup> 相比之下，差值的置信区间不作相等性假定，因此使用非合并标准误 \( \sqrt{\hat{p}_1(1-\hat{p}_1)/n_1 + \hat{p}_2(1-\hat{p}_2)/n_2} \)。<sup>[3](https://mtstateintrostats.github.io/IntroStatTextbook/inference-two-props.html)</sup> 这就是为什么同一数据可能得出显著的检验结果和一个刚刚包含零的区间，反之亦然。

## 条件与有效性

z 检验依赖于二项分布的正态近似，由中心极限定理提供依据。需要检查两个条件：观察值在组内和组间必须独立，且成功-失败条件必须成立，即在合并比例下每组中成功和失败的期望计数至少为 10。<sup>[3](https://mtstateintrostats.github.io/IntroStatTextbook/inference-two-props.html)</sup> 教科书和软件所述的阈值各不相同；正态近似的一个常见规则是 \( n_1 p_1 > 5 \) 且 \( n_2 p_2 > 5 \)。<sup>[4](https://pmc.ncbi.nlm.nih.gov/articles/PMC4868880/)</sup>

当期望计数较小时，近似的准确性下降，应优先采用精确方法。费希尔精确检验是常规的小样本替代方法，统计软件包会在任何期望单元格计数低于 5 时发出警告。<sup>[4](https://pmc.ncbi.nlm.nih.gov/articles/PMC4868880/)</sup> R 的 `prop.test` 提供耶茨连续性校正，使卡方版本更为保守；该校正仅在不超过样本比例差值的绝对值时才被应用。<sup>[6](https://www.rdocumentation.org/packages/stats/versions/3.3.2/topics/prop.test)</sup>

## 与其他检验的关系

对于双侧检验，双样本比例 z 检验与 2×2 表上的皮尔逊独立性或齐性卡方检验是等价的：卡方统计量是 z 统计量的平方，两者都源自相同的正态近似，在均未进行连续性校正计算时产生相同的 p 值。<sup>[2](https://www.statsmodels.org/stable/generated/statsmodels.stats.proportion.proportions_ztest.html)</sup><sup> • </sup><sup>[4](https://pmc.ncbi.nlm.nih.gov/articles/PMC4868880/)</sup>

## 样本量与功效

规划一项将用 z 检验分析的研究使用相同的正态近似。对于等量分配，在双侧 \( \alpha = 0.05 \) 和 80% 功效下检验比例 \( p_1 \) 和 \( p_2 \)，一个 \( p_1 = 0.2 \)、\( p_2 = 0.3 \) 的算例得出每组约 291 名受试者，而软件 G*Power 给出类似数字 294。<sup>[4](https://pmc.ncbi.nlm.nih.gov/articles/PMC4868880/)</sup> R 的 `power.prop.test` 可由其余参数计算样本量、功效、显著性水平或两个比例中的任意一个。<sup>[7](https://stat.ethz.ch/R-manual/R-devel/RHOME/library/stats/html/power.prop.test.html)</sup> 当预计期望计数较小时，样本量规划转向基于费希尔精确检验的计算，这需要软件而非闭式公式。<sup>[4](https://pmc.ncbi.nlm.nih.gov/articles/PMC4868880/)</sup>

## 解释时的注意事项

显著的 z 检验确立了该差异在原假设下不太可能出现；它并不衡量效应的大小或重要性。美国统计协会关于 p 值的声明指出，只要样本量足够大，任何效应无论多么微小都可能产生一个很小的 p 值，而单独来看接近 0.05 的 p 值仅提供反对原假设的弱证据。<sup>[8](https://www.stat.berkeley.edu/~aldous/Real_World/ASA_statement.pdf)</sup> 将观察到的差值连同置信区间与检验一起报告可以直接回应这一问题。<sup>[3](https://mtstateintrostats.github.io/IntroStatTextbook/inference-two-props.html)</sup>

**重复检验会膨胀错误率。** z 检验的名义显著性水平假定它是在计划样本量的数据上执行一次。在 A/B 测试中，反复检查结果并在 p 值首次降至 0.05 以下时停止，这种做法称为偷看（peeking），会使实际假阳性率远高于名义水平；在 \( \alpha = 0.05 \) 下对双样本比例 z 检验进行每日偷看的模拟产生约 25% 至 40% 的假阳性率。序贯检验方法在仍然允许提前停止的同时恢复了有效的错误控制。<sup>[9](https://abc.tools/sim/peeking-simulator/)</sup><sup> • </sup><sup>[10](https://docs.statsig.com/experiments/advanced-setup/sequential-testing)</sup> 在受监管的临床试验中，同样的担忧表现为多重性：在未加校正的情况下对多个终点各自以 \( \alpha = 0.05 \) 进行检验，会增加得出虚假有利结论的总体概率，这就是监管机构要求前瞻性多重性控制的原因。<sup>[11](https://www.fda.gov/regulatory-information/search-fda-guidance-documents/multiple-endpoints-clinical-trials)</sup>

## References

1. [Z-Test for Two Proportions, Social Science Statistics](https://www.socscistatistics.com/tutorials/z-test-two-proportions/)
2. [statsmodels.stats.proportion.proportions_ztest, statsmodels 0.15.0 documentation](https://www.statsmodels.org/stable/generated/statsmodels.stats.proportion.proportions_ztest.html)
3. [Chapter 15: Inference for comparing two proportions, Montana State Introductory Statistics with R](https://mtstateintrostats.github.io/IntroStatTextbook/inference-two-props.html)
4. [Statistical notes for clinical researchers: Sample size calculation 2. Comparison of two independent proportions, PMC](https://pmc.ncbi.nlm.nih.gov/articles/PMC4868880/)
5. [Two Proportion Z-Test: Definition, Formula, and Example, Statology](https://www.statology.org/two-proportion-z-test/)
6. [prop.test function, RDocumentation](https://www.rdocumentation.org/packages/stats/versions/3.3.2/topics/prop.test)
7. [power.prop.test, R stats documentation](https://stat.ethz.ch/R-manual/R-devel/RHOME/library/stats/html/power.prop.test.html)
8. [The ASA's Statement on p-Values: Context, Process, and Purpose](https://www.stat.berkeley.edu/~aldous/Real_World/ASA_statement.pdf)
9. [A/B Test Peeking Simulator, ABC Tools](https://abc.tools/sim/peeking-simulator/)
10. [Frequentist Sequential Testing, Statsig Docs](https://docs.statsig.com/experiments/advanced-setup/sequential-testing)
11. [Multiple Endpoints in Clinical Trials, Guidance for Industry, FDA (October 2022)](https://www.fda.gov/regulatory-information/search-fda-guidance-documents/multiple-endpoints-clinical-trials)

---
*Initially written Sep 17, 2026 · Reviewed: Oct 15, 2026 · Edited: Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 物质世界与数学 › 数学与统计学 › 统计学与概率论 › Statistical inference, estimation, sampling, and testing › Hypothesis testing › Sequential tests and stopping-based inference

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/two-proportion-z-test

English original: https://www.edgepedia.org/two-proportion-z-test
