scipy.stats.
binomtest#
- scipy.stats.binomtest(k, n, p=0.5, alternative='two-sided')[source]#
执行成功概率为 p 的检验。
二项检验 [1] 是对 Bernoulli 实验中成功概率为 p 的零假设的检验。
有关测试的详细信息可以在许多统计文本中找到,例如 [2] 的第 24.5 节。
- 参数:
- kint
成功的次数。
- nint
试验的次数。
- pfloat, optional
假设的成功概率,即成功的预期比例。该值必须在区间
0 <= p <= 1
内。默认值为p = 0.5
。- alternative{‘two-sided’, ‘greater’, ‘less’}, optional
指示备择假设。默认值为 ‘two-sided’。
- 返回值:
- result
BinomTestResult
实例 返回值是一个具有以下属性的对象
- kint
成功的次数(从
binomtest
输入复制)。- nint
试验的次数(从
binomtest
输入复制)。- alternativestr
指示在
binomtest
的输入中指定的备择假设。它将是'two-sided'
、'greater'
或'less'
之一。- statisticfloat
成功的比例的估计值。
- pvaluefloat
假设检验的 p 值。
该对象具有以下方法
- proportion_ci(confidence_level=0.95, method=’exact’)
计算
statistic
的置信区间。
- result
说明
在版本 1.7.0 中添加。
参考文献
[2]Jerrold H. Zar, Biostatistical Analysis (第五版), Prentice Hall, Upper Saddle River, New Jersey USA (2010)
示例
>>> from scipy.stats import binomtest
一家汽车制造商声称其汽车中不安全车辆不超过 10%。检查了 15 辆汽车的安全性,发现 3 辆不安全。检验制造商的声明
>>> result = binomtest(3, n=15, p=0.1, alternative='greater') >>> result.pvalue 0.18406106910639114
由于返回的 p 值大于 5% 的临界值,因此无法在 5% 的显着性水平上拒绝原假设。
检验统计量等于估计的比例,即简单的
3/15
>>> result.statistic 0.2
我们可以使用结果的 proportion_ci() 方法来计算估计的置信区间
>>> result.proportion_ci(confidence_level=0.95) ConfidenceInterval(low=0.05684686759024681, high=1.0)