binned_binom_proportion#
- astropy.stats.binned_binom_proportion(x: ArrayLike, success: ArrayLike, bins: int | ArrayLike = 10, range: tuple[float, float] | None = None, confidence_level: float = 0.68269, interval: Literal['wilson', 'jeffreys', 'flat', 'wald'] = 'wilson') tuple[NDArray, NDArray, NDArray, NDArray][源代码]#
连续变量的二项比例与区间
x.给定一组数据点对,其中
x值是连续分布的success值为二项式(“成功/失败”或“真/假”),根据x计算每个仓位中的二项式比例(成功率分数)和置信区间。- 参数:
- x : sequencePython :序列
价值观。
- success : sequence 的 boolPython :布尔值序列
- bins :
int或 sequence 的 scalar ,可选Python:int或python:标量序列,可选 如果bins是一个int,它定义给定范围(默认为10)中等宽存储库的数量。如果箱子是一个序列,它定义了箱子边缘,包括最右边的边缘,允许不均匀的箱子宽度(在这种情况下,“范围”被忽略)。
- range : (
float,float),可选(float,float), optional 垃圾箱的上限和下限。如果
None(默认),范围设置为(x.min(), x.max()). 超出范围的值将被忽略。- confidence_level :
float,可选Python:Float,可选 必须在范围内 [0, 1] 。置信区间中的期望概率内容
(p - perr[0], p + perr[1])在每个垃圾箱里。默认值为0.68269。- interval{'wilson'、'jeffreys'、'flat'、'wald'},可选
用于计算每个仓位中二项比例的置信区间的公式。看到了吗
binom_conf_interval对于间隔的定义。‘wilson’、‘jeffreys’和‘flat’区间通常给出相似的结果。”wilson应该更快一些,而jeffreys和flat稍微好一点,但在假设的先验值上有所不同。一般不建议使用“wald”间隔。它是为了比较目的而提供的。默认值是'wilson'。
- 返回:
参见
binom_conf_interval用于估计每个箱子中的置信区间的函数。
笔记
此函数需要
scipy适用于所有时间间隔类型。实例
假设我们希望估算一次探测天文源的效率,作为一个震级的函数(即,在给定的星等下探测到一个源的概率)。在实际情况下,我们可以准备大量随机选取的震源,注入模拟图像,然后记录在还原管道末端检测到的信号。作为一个玩具例子,我们生成100个随机选择的震级在20到30之间的数据点,并用已知的检测函数“观察”它们(这里是误差函数,在25级时有50%的检测概率):
>>> from scipy.special import erf >>> from scipy.stats.distributions import binom >>> def true_efficiency(x): ... return 0.5 - 0.5 * erf((x - 25.) / 2.) >>> mag = 20. + 10. * np.random.rand(100) >>> detected = binom.rvs(1, true_efficiency(mag)) >>> bins, binshw, p, perr = binned_binom_proportion(mag, detected, bins=20) >>> plt.errorbar(bins, p, xerr=binshw, yerr=perr, ls='none', marker='o', ... label='estimate')
上面的例子使用Wilson置信区间来计算不确定性
perr在每个箱子中(参见binom_conf_interval). 一个常用的替代方法是Wald区间。然而,当效率接近0或1时,Wald区间会给出无意义的不确定性,因此 not 推荐。作为说明,下面的示例显示了与上面相同的数据,但是使用Wald间隔而不是Wilson间隔来计算perr:>>> bins, binshw, p, perr = binned_binom_proportion(mag, detected, bins=20, ... interval='wald') >>> plt.errorbar(bins, p, xerr=binshw, yerr=perr, ls='none', marker='o', ... label='estimate')