SciPy 1.12 中文文档(四十四)
scipy.special.pdtr
原文链接:
docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.pdtr.html#scipy.special.pdtr
scipy.special.pdtr(k, m, out=None) = <ufunc 'pdtr'>
泊松累积分布函数
定义为泊松分布随机变量事件率为(m)时小于或等于(k)的概率。更具体地说,这实际上等于[1]
[\exp(-m) \sum_{j = 0}^{\lfloor{k}\rfloor} \frac{m^j}{j!}.]
参数:
k数组样式
发生次数(非负实数)
m数组样式
形状参数(非负实数)
outndarray,可选
可选的输出数组以获得函数结果
返回:
标量或者 ndarray
泊松累积分布函数的值
另请参见
泊松生存函数
相对于k
相对于m的pdtr的反函数
参考文献
[1]
示例
>>> import numpy as np
>>> import scipy.special as sc
这是一个累积分布函数,因此随着k趋向于无穷大,它单调地收敛到 1。
>>> sc.pdtr([1, 10, 100, np.inf], 1)
array([0.73575888, 0.99999999, 1\. , 1\. ])
在整数处不连续,在整数之间保持恒定。
>>> sc.pdtr([1, 1.5, 1.9, 2], 1)
array([0.73575888, 0.73575888, 0.73575888, 0.9196986 ])
scipy.special.pdtrik
原文:
docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.pdtrik.html#scipy.special.pdtrik
scipy.special.pdtrik(p, m, out=None) = <ufunc 'pdtrik'>
相对于 m 的 pdtr 的逆。
参数:
m array_like
形状参数(非负实数)
p array_like
概率
out ndarray,可选
函数结果的可选输出数组
返回:
标量或 ndarray
发生次数 k 满足 pdtr(k, m) = p 的数量
另见
pdtr
Poisson 累积分布函数
pdtrc
Poisson 生存函数
pdtri
相对于 m 的逆函数 pdtr 的逆
scipy.special.pdtr
原文链接:
docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.pdtr.html#scipy.special.pdtr
scipy.special.pdtr(k, m, out=None) = <ufunc 'pdtr'>
泊松累积分布函数。
定义为泊松分布随机变量事件率为 (m) 小于或等于 (k) 的概率。更具体地说,这将变为 [1]
[\exp(-m) \sum_{j = 0}^{\lfloor{k}\rfloor} \frac{m^j}{j!}.]
参数:
k类似数组
出现次数(非负实数)
m类似数组
形状参数(非负实数)
out数组,可选
函数结果的可选输出数组
返回:
标量或数组
泊松累积分布函数的值
另请参见
泊松生存函数
相对于 k 的 pdtr 的逆
相对于 m 的 pdtr 的逆
参考文献
[1]
en.wikipedia.org/wiki/Poisson_distribution
示例
>>> import numpy as np
>>> import scipy.special as sc
这是一个累积分布函数,因此随着 k 趋向无穷大,它单调收敛于 1。
>>> sc.pdtr([1, 10, 100, np.inf], 1)
array([0.73575888, 0.99999999, 1\. , 1\. ])
在整数处不连续,在整数之间恒定。
>>> sc.pdtr([1, 1.5, 1.9, 2], 1)
array([0.73575888, 0.73575888, 0.73575888, 0.9196986 ])
scipy.special.stdtr
原文:
docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.stdtr.html#scipy.special.stdtr
scipy.special.stdtr(df, t, out=None) = <ufunc 'stdtr'>
学生 t 分布累积分布函数
返回积分:
[\frac{\Gamma((df+1)/2)}{\sqrt{\pi df} \Gamma(df/2)} \int_{-\infty}^t (1+x²/df)^{-(df+1)/2}, dx]
参数:
df数组样式
自由度
t数组样式
积分的上限
out ndarray,可选
函数结果的可选输出数组
返回:
标量或 ndarray
t 的学生 CDF 的值
另请参阅
stdtridf
与df相关的 stdtr 的逆
stdtrit
与t相关的 stdtr 的逆
scipy.stats.t
学生 t 分布
注
学生 t 分布也可以作为scipy.stats.t使用。与scipy.stats.t的cdf方法相比,直接调用stdtr可以提高性能(见下面的最后一个示例)。
示例
计算df=3时在t=1处的函数。
>>> import numpy as np
>>> from scipy.special import stdtr
>>> import matplotlib.pyplot as plt
>>> stdtr(3, 1)
0.8044988905221148
绘制三个不同自由度的函数。
>>> x = np.linspace(-10, 10, 1000)
>>> fig, ax = plt.subplots()
>>> parameters = [(1, "solid"), (3, "dashed"), (10, "dotted")]
>>> for (df, linestyle) in parameters:
... ax.plot(x, stdtr(df, x), ls=linestyle, label=f"$df={df}$")
>>> ax.legend()
>>> ax.set_title("Student t distribution cumulative distribution function")
>>> plt.show()
通过为df提供 NumPy 数组或列表,可以同时计算多个自由度的函数。
>>> stdtr([1, 2, 3], 1)
array([0.75 , 0.78867513, 0.80449889])
通过为df和t提供适合广播的形状的数组,可以同时在几个不同的自由度上计算几个点的函数值。在 3 个自由度的情况下,为 4 个点计算stdtr,得到一个形状为 3x4 的数组。
>>> dfs = np.array([[1], [2], [3]])
>>> t = np.array([2, 4, 6, 8])
>>> dfs.shape, t.shape
((3, 1), (4,))
>>> stdtr(dfs, t)
array([[0.85241638, 0.92202087, 0.94743154, 0.96041658],
[0.90824829, 0.97140452, 0.98666426, 0.99236596],
[0.93033702, 0.98599577, 0.99536364, 0.99796171]])
t 分布也可以作为scipy.stats.t使用。直接调用stdtr比调用scipy.stats.t的cdf方法要快得多。为了获得相同的结果,必须使用以下参数化方式:scipy.stats.t(df).cdf(x) = stdtr(df, x)。
>>> from scipy.stats import t
>>> df, x = 3, 1
>>> stdtr_result = stdtr(df, x) # this can be faster than below
>>> stats_result = t(df).cdf(x)
>>> stats_result == stdtr_result # test that results are equal
True
scipy.special.stdtridf
scipy.special.stdtridf(p, t, out=None) = <ufunc 'stdtridf'>
stdtr的逆与 df
返回参数 df,使得 stdtr(df, t) 等于 p。
参数:
p,类似于数组
概率
t,类似于数组
积分的上限
out,可选项
函数结果的可选输出数组
返回:
df,标量或数组
值 df,使得 stdtr(df, t) == p
参见
stdtr
学生 t 分布函数
stdtrit
t的逆 stdtr
scipy.stats.t
学生 t 分布
示例
计算一个参数集的学生 t 累积分布函数。
>>> from scipy.special import stdtr, stdtridf
>>> df, x = 5, 2
>>> cdf_value = stdtr(df, x)
>>> cdf_value
0.9490302605850709
验证当给定 CDF 值和 x 时,stdtridf 恢复原始值 df。
>>> stdtridf(cdf_value, x)
5.0
scipy.special.stdtr
原文链接:
docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.stdtr.html#scipy.special.stdtr
scipy.special.stdtr(df, t, out=None) = <ufunc 'stdtr'>
学生 t 分布累积分布函数
返回积分:
[\frac{\Gamma((df+1)/2)}{\sqrt{\pi df} \Gamma(df/2)} \int_{-\infty}^t (1+x²/df)^{-(df+1)/2}, dx]
参数:
dfarray_like
自由度
tarray_like
积分的上界
outndarray,可选
用于输出函数结果的可选输出数组
返回:
标量或 ndarray
t 处的学生 t CDF 值
另见
stdtridf
stdtr 的逆函数关于df
stdtrit
stdtr 的逆函数关于t
scipy.stats.t
学生 t 分布
注意
学生 t 分布也可以作为scipy.stats.t调用。与scipy.stats.t的cdf方法相比,直接调用stdtr可以提高性能(见下面的最后一个例子)。
示例
在df=3和t=1处计算函数。
>>> import numpy as np
>>> from scipy.special import stdtr
>>> import matplotlib.pyplot as plt
>>> stdtr(3, 1)
0.8044988905221148
绘制三种不同自由度的函数。
>>> x = np.linspace(-10, 10, 1000)
>>> fig, ax = plt.subplots()
>>> parameters = [(1, "solid"), (3, "dashed"), (10, "dotted")]
>>> for (df, linestyle) in parameters:
... ax.plot(x, stdtr(df, x), ls=linestyle, label=f"$df={df}$")
>>> ax.legend()
>>> ax.set_title("Student t distribution cumulative distribution function")
>>> plt.show()
通过为df提供 NumPy 数组或列表,可以同时计算几个自由度的函数:
>>> stdtr([1, 2, 3], 1)
array([0.75 , 0.78867513, 0.80449889])
可以通过为df和t提供广播兼容形状的数组,在几个不同自由度同时计算几个点的函数。计算 3 自由度下 4 点的stdtr,得到形状为 3x4 的数组。
>>> dfs = np.array([[1], [2], [3]])
>>> t = np.array([2, 4, 6, 8])
>>> dfs.shape, t.shape
((3, 1), (4,))
>>> stdtr(dfs, t)
array([[0.85241638, 0.92202087, 0.94743154, 0.96041658],
[0.90824829, 0.97140452, 0.98666426, 0.99236596],
[0.93033702, 0.98599577, 0.99536364, 0.99796171]])
学生 t 分布也可以作为scipy.stats.t调用。直接调用stdtr比调用scipy.stats.t的cdf方法速度要快得多。为了得到相同的结果,必须使用以下参数化方式:scipy.stats.t(df).cdf(x) = stdtr(df, x)。
>>> from scipy.stats import t
>>> df, x = 3, 1
>>> stdtr_result = stdtr(df, x) # this can be faster than below
>>> stats_result = t(df).cdf(x)
>>> stats_result == stdtr_result # test that results are equal
True
scipy.special.stdtrit
原文:
docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.stdtrit.html#scipy.special.stdtrit
scipy.special.stdtrit(df, p, out=None) = <ufunc 'stdtrit'>
学生 t 分布的p分位数。
此函数是学生 t 分布累积分布函数的逆,返回t,使得stdtr(df, t) = p。
返回参数t,使得 stdtr(df, t)等于p。
参数:
dfarray_like
自由度
parray_like
概率
outndarray,可选
可选的输出数组用于函数结果
返回:
t标量或 ndarray
根据stdtr(df, t) == p计算使得t等于p的值。
另请参阅
stdtr
学生 t 分布的累积分布函数
stdtridf
df的 stdtr 的逆
scipy.stats.t
学生 t 分布
注释
学生 t 分布也可以作为scipy.stats.t使用。直接调用stdtrit相对于scipy.stats.t的ppf方法可以提高性能(见下面的最后一个例子)。
示例
stdtrit表示学生 t 分布的累积分布函数的逆,该函数可作为stdtr获得。在此,我们计算df在x=1时的累积分布函数。stdtrit然后返回 1,直到浮点误差给出相同的值用于df和计算的累积分布函数值。
>>> import numpy as np
>>> from scipy.special import stdtr, stdtrit
>>> import matplotlib.pyplot as plt
>>> df = 3
>>> x = 1
>>> cdf_value = stdtr(df, x)
>>> stdtrit(df, cdf_value)
0.9999999994418539
绘制三个不同自由度的函数。
>>> x = np.linspace(0, 1, 1000)
>>> parameters = [(1, "solid"), (2, "dashed"), (5, "dotted")]
>>> fig, ax = plt.subplots()
>>> for (df, linestyle) in parameters:
... ax.plot(x, stdtrit(df, x), ls=linestyle, label=f"$df={df}$")
>>> ax.legend()
>>> ax.set_ylim(-10, 10)
>>> ax.set_title("Student t distribution quantile function")
>>> plt.show()
通过提供df的 NumPy 数组或列表,可以同时计算几个自由度的函数。
>>> stdtrit([1, 2, 3], 0.7)
array([0.72654253, 0.6172134 , 0.58438973])
通过提供形状兼容进行广播的df和p数组,可以同时计算几个不同自由度的点的函数值。在 3 个自由度的情况下为 4 个点计算stdtrit,返回形状为 3x4 的数组。
>>> dfs = np.array([[1], [2], [3]])
>>> p = np.array([0.2, 0.4, 0.7, 0.8])
>>> dfs.shape, p.shape
((3, 1), (4,))
>>> stdtrit(dfs, p)
array([[-1.37638192, -0.3249197 , 0.72654253, 1.37638192],
[-1.06066017, -0.28867513, 0.6172134 , 1.06066017],
[-0.97847231, -0.27667066, 0.58438973, 0.97847231]])
学生 t 分布也可以作为scipy.stats.t使用。直接调用stdtrit比调用scipy.stats.t的ppf方法更快。要获得相同的结果,必须使用以下参数化:scipy.stats.t(df).ppf(x) = stdtrit(df, x)。
>>> from scipy.stats import t
>>> df, x = 3, 0.5
>>> stdtrit_result = stdtrit(df, x) # this can be faster than below
>>> stats_result = t(df).ppf(x)
>>> stats_result == stdtrit_result # test that results are equal
True
scipy.special.chdtr
原文:
docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.chdtr.html#scipy.special.chdtr
scipy.special.chdtr(v, x, out=None) = <ufunc 'chdtr'>
卡方累积分布函数。
返回自由度为v的卡方概率密度函数左尾(从 0 到x)下的面积:
[\frac{1}{2^{v/2} \Gamma(v/2)} \int_0^x t^{v/2 - 1} e^{-t/2} dt]
这里(\Gamma)是 Gamma 函数;见gamma。此积分可用正则化的下不完全 Gamma 函数gammainc表示为gammainc(v / 2, x / 2)。[1]
参数:
varray_like
自由度。
xarray_like
积分的上界。
outndarray, optional
可选的输出数组以获取函数结果。
返回:
标量或 ndarray
累积分布函数的值。
另请参阅
chdtrc, chdtri, chdtriv, gammainc
参考文献
[1]
卡方分布,www.itl.nist.gov/div898/handbook/eda/section3/eda3666.htm
示例
>>> import numpy as np
>>> import scipy.special as sc
可以用正则化的下不完全 Gamma 函数表示。
>>> v = 1
>>> x = np.arange(4)
>>> sc.chdtr(v, x)
array([0\. , 0.68268949, 0.84270079, 0.91673548])
>>> sc.gammainc(v / 2, x / 2)
array([0\. , 0.68268949, 0.84270079, 0.91673548])
scipy.special.chdtrc
原文:
docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.chdtrc.html#scipy.special.chdtrc
scipy.special.chdtrc(v, x, out=None) = <ufunc 'chdtrc'>
卡方生存函数。
返回自由度为 v 的卡方概率密度函数右尾部分(从 x 到无穷大)下面积分的面积:
[\frac{1}{2^{v/2} \Gamma(v/2)} \int_x^\infty t^{v/2 - 1} e^{-t/2} dt]
这里 (\Gamma) 是 Gamma 函数;参见gamma。这个积分可以用常规化的上不完全 Gamma 函数gammaincc表示为 gammaincc(v / 2, x / 2)。[1]
参数:
v 数组型
自由度。
x 数组型
积分的下限。
out ndarray,可选
可选输出数组的函数结果。
返回值:
标量或 ndarray
生存函数的值。
参见
chdtr, chdtri, chdtriv, gammaincc
参考文献
[1]
卡方分布,www.itl.nist.gov/div898/handbook/eda/section3/eda3666.htm
示例
>>> import numpy as np
>>> import scipy.special as sc
可以用常规化的上不完全 Gamma 函数表示。
>>> v = 1
>>> x = np.arange(4)
>>> sc.chdtrc(v, x)
array([1\. , 0.31731051, 0.15729921, 0.08326452])
>>> sc.gammaincc(v / 2, x / 2)
array([1\. , 0.31731051, 0.15729921, 0.08326452])
scipy.special.chdtri
原文:
docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.chdtri.html#scipy.special.chdtri
scipy.special.chdtri(v, p, out=None) = <ufunc 'chdtri'>
相对于x,与chdtrc相反。
返回x,使得chdtrc(v, x) == p。
参数:
varray_like
自由度。
parray_like
概率。
outndarray,可选
函数结果的可选输出数组。
返回:
x标量或 ndarray
使卡方随机变量的概率(自由度为v)大于x的值等于p。
另请参阅
chdtrc,chdtr,chdtriv
参考文献
[1]
卡方分布,www.itl.nist.gov/div898/handbook/eda/section3/eda3666.htm
示例
>>> import scipy.special as sc
它反转了chdtrc。
>>> v, p = 1, 0.3
>>> sc.chdtrc(v, sc.chdtri(v, p))
0.3
>>> x = 1
>>> sc.chdtri(v, sc.chdtrc(v, x))
1.0
scipy.special.chdtrc
原文链接:
docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.chdtrc.html#scipy.special.chdtrc
scipy.special.chdtrc(v, x, out=None) = <ufunc 'chdtrc'>
卡方生存函数。
返回卡方概率密度函数右尾(从 x 到无穷大)下的面积,具有 v 自由度:
[\frac{1}{2^{v/2} \Gamma(v/2)} \int_x^\infty t^{v/2 - 1} e^{-t/2} dt]
这里 (\Gamma) 是伽马函数;参见 gamma。这个积分可以用正则化的上不完全伽马函数 gammaincc 表示为 gammaincc(v / 2, x / 2)。 [1]
参数:
varray_like
自由度。
xarray_like
积分的下界。
outndarray, 可选
该函数结果的可选输出数组。
返回:
标量或 ndarray
生存函数的值。
见下文
chdtr, chdtri, chdtriv, gammaincc
参考文献
[1]
卡方分布,www.itl.nist.gov/div898/handbook/eda/section3/eda3666.htm
示例
>>> import numpy as np
>>> import scipy.special as sc
可以用正则化的上不完全伽马函数来表示。
>>> v = 1
>>> x = np.arange(4)
>>> sc.chdtrc(v, x)
array([1\. , 0.31731051, 0.15729921, 0.08326452])
>>> sc.gammaincc(v / 2, x / 2)
array([1\. , 0.31731051, 0.15729921, 0.08326452])
scipy.special.chdtriv
原文链接:
docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.chdtriv.html#scipy.special.chdtriv
scipy.special.chdtriv(p, x, out=None) = <ufunc 'chdtriv'>
关于v的chdtr的反函数。
返回v,使得chdtr(v, x) == p。
参数:
parray_like
卡方随机变量小于或等于x的概率。
xarray_like
非负输入。
outndarray,可选
可选的输出数组,用于存储函数结果。
返回:
标量或 ndarray
自由度。
另见
参考文献
[1]
卡方分布,www.itl.nist.gov/div898/handbook/eda/section3/eda3666.htm
示例
>>> import scipy.special as sc
它反转chdtr。
>>> p, x = 0.5, 1
>>> sc.chdtr(sc.chdtriv(p, x), x)
0.5000000000202172
>>> v = 1
>>> sc.chdtriv(sc.chdtr(v, x), v)
1.0000000000000013
scipy.special.chdtr
原文:
docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.chdtr.html#scipy.special.chdtr
scipy.special.chdtr(v, x, out=None) = <ufunc 'chdtr'>
卡方累积分布函数。
返回自由度为v的卡方概率密度函数左尾(从 0 到x)下的面积:
[\frac{1}{2^{v/2} \Gamma(v/2)} \int_0^x t^{v/2 - 1} e^{-t/2} dt]
这里(\Gamma)是 Gamma 函数;参见gamma。这个积分可以用正则化的下不完全 Gamma 函数gammainc表示为gammainc(v / 2, x / 2)。[1]
参数:
varray_like
自由度。
xarray_like
积分的上界。
outndarray,可选
函数结果的可选输出数组。
返回:
标量或 ndarray
累积分布函数的值。
另请参见
chdtrc,chdtri,chdtriv,gammainc
参考文献
[1]
卡方分布,www.itl.nist.gov/div898/handbook/eda/section3/eda3666.htm
示例
>>> import numpy as np
>>> import scipy.special as sc
可以用正则化的下不完全 Gamma 函数表示。
>>> v = 1
>>> x = np.arange(4)
>>> sc.chdtr(v, x)
array([0\. , 0.68268949, 0.84270079, 0.91673548])
>>> sc.gammainc(v / 2, x / 2)
array([0\. , 0.68268949, 0.84270079, 0.91673548])
scipy.special.chndtr
原文:
docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.chndtr.html#scipy.special.chndtr
scipy.special.chndtr(x, df, nc, out=None) = <ufunc 'chndtr'>
非中心卡方累积分布函数
累积分布函数由以下公式给出:
[P(\chi^{\prime 2} \vert \nu, \lambda) =\sum_{j=0}^{\infty} e^{-\lambda /2} \frac{(\lambda /2)^j}{j!} P(\chi^{\prime 2} \vert \nu + 2j),]
其中 (\nu > 0) 是自由度 (df),(\lambda \geq 0) 是非中心参数 (nc)。
参数:
x array_like
积分的上限;必须满足x >= 0
df array_like
自由度;必须满足df > 0
nc array_like
非中心参数;必须满足nc >= 0
out ndarray,可选
可选的输出数组,用于存储函数结果
返回值:
x 标量或者 ndarray
非中心卡方累积分布函数的值。
另请参阅
chndtrix, chndtridf, chndtrinc
scipy.special.chndtridf
scipy.special.chndtridf(x, p, nc, out=None) = <ufunc 'chndtridf'>
chndtr 的逆函数 vs df
使用搜索找到一个值为 df 的值,以得到所需的 p 值。
参数:
x 数组或类似数组
积分的上界;必须满足 x >= 0
p 数组或类似数组
概率;必须满足 0 <= p < 1
nc 数组或类似数组
非中心参数;必须满足 nc >= 0
out ndarray,可选
函数结果的可选输出数组
返回:
df 标量或者 ndarray
自由度
另请参阅
scipy.special.chndtr
原文:
docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.chndtr.html#scipy.special.chndtr
scipy.special.chndtr(x, df, nc, out=None) = <ufunc 'chndtr'>
非中心卡方分布累积分布函数
累积分布函数由以下给出:
[P(\chi^{\prime 2} \vert \nu, \lambda) =\sum_{j=0}^{\infty} e^{-\lambda /2} \frac{(\lambda /2)^j}{j!} P(\chi^{\prime 2} \vert \nu + 2j),]
其中 (\nu > 0) 是自由度 (df),(\lambda \geq 0) 是非中心参数 (nc)。
参数:
xarray_like
积分的上限;必须满足 x >= 0
dfarray_like
自由度;必须满足 df > 0
ncarray_like
非中心参数;必须满足 nc >= 0
outndarray, 可选
可选的输出数组用于函数结果
返回:
x标量或数组
非中心卡方分布累积分布函数的值。
另见
chndtrix, chndtridf, chndtrinc
scipy.special.chndtrinc
scipy.special.chndtrinc(x, df, p, out=None) = <ufunc 'chndtrinc'>
逆函数为chndtr与nc的比例
使用搜索计算df的值,以得到期望的p值。
参数:
x数组类型
积分的上限;必须满足x >= 0
df数组类型
自由度;必须满足df > 0
p数组类型
概率;必须满足0 <= p < 1
out数组类型,可选
可选的输出数组用于函数结果
返回:
nc标量或数组
非中心性
另请参见
chndtr, chndtrix, chndtrinc
scipy.special.chndtr
原文链接:
docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.chndtr.html#scipy.special.chndtr
scipy.special.chndtr(x, df, nc, out=None) = <ufunc 'chndtr'>
非中心卡方累积分布函数
累积分布函数由以下给出:
[P(\chi^{\prime 2} \vert \nu, \lambda) =\sum_{j=0}^{\infty} e^{-\lambda /2} \frac{(\lambda /2)^j}{j!} P(\chi^{\prime 2} \vert \nu + 2j),]
其中 (\nu > 0) 是自由度(df),(\lambda \geq 0) 是非中心参数(nc)。
参数:
xarray_like
积分的上限;必须满足 x >= 0
dfarray_like
自由度;必须满足 df > 0
ncarray_like
非中心参数;必须满足 nc >= 0
outndarray,可选
函数结果的可选输出数组
返回:
x标量或数组
非中心卡方累积分布函数的值。
另请参阅
chndtrix, chndtridf, chndtrinc
scipy.special.chndtrix
scipy.special.chndtrix(p, df, nc, out=None) = <ufunc 'chndtrix'>
逆chndtr对应的x
使用搜索计算得到使得p的概率为目标的x的值。
参数:
parray_like
概率;必须满足 0 <= p < 1
dfarray_like
自由度;必须满足 df > 0
ncarray_like
非中心参数;必须满足 nc >= 0
outndarray,可选
函数结果的可选输出数组
返回:
x标量或 ndarray
使得自由度为df、非中心度nc的非中心卡方随机变量大于x的概率等于p的值。
参见
scipy.special.chndtr
原文:
docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.chndtr.html#scipy.special.chndtr
scipy.special.chndtr(x, df, nc, out=None) = <ufunc 'chndtr'>
非中心卡方累积分布函数
累积分布函数如下所示:
[P(\chi^{\prime 2} \vert \nu, \lambda) =\sum_{j=0}^{\infty} e^{-\lambda /2} \frac{(\lambda /2)^j}{j!} P(\chi^{\prime 2} \vert \nu + 2j),]
其中 (\nu > 0) 是自由度(df),(\lambda \geq 0) 是非中心参数(nc)。
参数:
x数组
积分的上限;必须满足x >= 0
df数组
自由度;必须满足df > 0
nc数组
非中心参数;必须满足nc >= 0
out数组,可选
函数结果的可选输出数组
返回:
x标量或数组
非中心卡方累积分布函数的值。
另请参见
scipy.special.smirnov
原文链接:
docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.smirnov.html#scipy.special.smirnov
scipy.special.smirnov(n, d, out=None) = <ufunc 'smirnov'>
Kolmogorov-Smirnov 互补累积分布函数
返回确切的 Kolmogorov-Smirnov 互补累积分布函数(也称为生存函数),Dn+(或 Dn-)的单侧相等性检验的理论分布和经验分布之间的最大差异的概率。它等于基于n个样本的理论分布和经验分布之间的最大差异大于 d 的概率。
参数:
nint
样本数量
dfloat array_like
经验 CDF(ECDF)与目标 CDF 之间的偏差。
outndarray,可选
函数结果的可选输出数组
返回:
标量或 ndarray
smirnov(n, d)的值,Prob(Dn+ >= d)(也是 Prob(Dn- >= d))
另请参见
smirnovi
分布的逆生存函数
scipy.stats.ksone
提供作为连续分布的功能
kolmogorov, kolmogi
用于双侧分布的函数
注意事项
smirnov被stats.kstest在 Kolmogorov-Smirnov 拟合度检验中使用。出于历史原因,此函数在scipy.special中公开,但实现最精确的 CDF/SF/PDF/PPF/ISF 计算的推荐方法是使用stats.ksone分布。
示例
>>> import numpy as np
>>> from scipy.special import smirnov
>>> from scipy.stats import norm
显示大小为 5 的样本至少大于等于 0、0.5 和 1.0 的间隙的概率。
>>> smirnov(5, [0, 0.5, 1.0])
array([ 1\. , 0.056, 0\. ])
将大小为 5 的样本与 N(0, 1)(均值为 0,标准差为 1)进行比较。
x是样本。
>>> x = np.array([-1.392, -0.135, 0.114, 0.190, 1.82])
>>> target = norm(0, 1)
>>> cdfs = target.cdf(x)
>>> cdfs
array([0.0819612 , 0.44630594, 0.5453811 , 0.57534543, 0.9656205 ])
构建经验 CDF 和 K-S 统计量(Dn+、Dn-、Dn)。
>>> n = len(x)
>>> ecdfs = np.arange(n+1, dtype=float)/n
>>> cols = np.column_stack([x, ecdfs[1:], cdfs, cdfs - ecdfs[:n],
... ecdfs[1:] - cdfs])
>>> with np.printoptions(precision=3):
... print(cols)
[[-1.392 0.2 0.082 0.082 0.118]
[-0.135 0.4 0.446 0.246 -0.046]
[ 0.114 0.6 0.545 0.145 0.055]
[ 0.19 0.8 0.575 -0.025 0.225]
[ 1.82 1\. 0.966 0.166 0.034]]
>>> gaps = cols[:, -2:]
>>> Dnpm = np.max(gaps, axis=0)
>>> print(f'Dn-={Dnpm[0]:f}, Dn+={Dnpm[1]:f}')
Dn-=0.246306, Dn+=0.224655
>>> probs = smirnov(n, Dnpm)
>>> print(f'For a sample of size {n} drawn from N(0, 1):',
... f' Smirnov n={n}: Prob(Dn- >= {Dnpm[0]:f}) = {probs[0]:.4f}',
... f' Smirnov n={n}: Prob(Dn+ >= {Dnpm[1]:f}) = {probs[1]:.4f}',
... sep='\n')
For a sample of size 5 drawn from N(0, 1):
Smirnov n=5: Prob(Dn- >= 0.246306) = 0.4711
Smirnov n=5: Prob(Dn+ >= 0.224655) = 0.5245
绘制经验 CDF 和标准正态 CDF。
>>> import matplotlib.pyplot as plt
>>> plt.step(np.concatenate(([-2.5], x, [2.5])),
... np.concatenate((ecdfs, [1])),
... where='post', label='Empirical CDF')
>>> xx = np.linspace(-2.5, 2.5, 100)
>>> plt.plot(xx, target.cdf(xx), '--', label='CDF for N(0, 1)')
添加标记 Dn+和 Dn-的垂直线。
>>> iminus, iplus = np.argmax(gaps, axis=0)
>>> plt.vlines([x[iminus]], ecdfs[iminus], cdfs[iminus], color='r',
... alpha=0.5, lw=4)
>>> plt.vlines([x[iplus]], cdfs[iplus], ecdfs[iplus+1], color='m',
... alpha=0.5, lw=4)
>>> plt.grid(True)
>>> plt.legend(framealpha=1, shadow=True)
>>> plt.show()
scipy.special.smirnovi
scipy.special.smirnovi(n, p, out=None) = <ufunc 'smirnovi'>
逆函数 smirnov
返回 d,使得 smirnov(n, d) == p,与 p 对应的临界值。
参数:
nint
样本数量
pfloat array_like
概率
outndarray,可选
函数结果的可选输出数组
返回:
标量或 ndarray
smirnovi(n, p) 的值(或值的集合),关键值。
另请参见
smirnov
分布的生存函数(SF)
scipy.stats.ksone
作为连续分布的功能
kolmogorov,kolmogi
两边分布的函数
scipy.stats.kstwobign
双边 Kolmogorov-Smirnov 分布,大 n
注意事项
stats.kstest 应用了 Kolmogorov-Smirnov 拟合优度检验中的smirnov。出于历史原因,此函数暴露在 scpy.special 中,但实现最精确的 CDF/SF/PDF/PPF/ISF 计算的推荐方法是使用 stats.ksone 分布。
示例
>>> from scipy.special import smirnovi, smirnov
>>> n = 24
>>> deviations = [0.1, 0.2, 0.3]
使用 smirnov 来计算给定样本数量和偏差的 Smirnov 分布的互补 CDF。
>>> p = smirnov(n, deviations)
>>> p
array([0.58105083, 0.12826832, 0.01032231])
逆函数 smirnovi(n, p) 返回 deviations。
>>> smirnovi(n, p)
array([0.1, 0.2, 0.3])
scipy.special.smirnov
原文链接:
docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.smirnov.html#scipy.special.smirnov
scipy.special.smirnov(n, d, out=None) = <ufunc 'smirnov'>
Kolmogorov-Smirnov 单侧累积分布函数
返回 Kolmogorov-Smirnov 单侧检验(即生存函数)的确切值 Dn+(或 Dn-),用于衡量经验分布与理论分布的一致性。它等于理论分布与基于 n 个样本的经验分布之间的最大差异大于 d 的概率。
参数:
n 整数
样本数量
d 浮点数数组
经验 CDF(ECDF)与目标 CDF 之间的偏差。
out ndarray,可选
可选的输出数组,用于函数结果
返回:
标量或者 ndarray
smirnov(n, d) 的值,Prob(Dn+ >= d)(也是 Prob(Dn- >= d))
参见
smirnovi
分布的逆生存函数
scipy.stats.ksone
提供连续分布的功能
kolmogorov,kolmogi
两侧分布的函数
注意:
smirnov 在 Kolmogorov-Smirnov 拟合优度检验中由 stats.kstest 应用。出于历史原因,此函数在 scpy.special 中公开,但建议以最准确的 CDF/SF/PDF/PPF/ISF 计算方式使用 stats.ksone 分布。
示例
>>> import numpy as np
>>> from scipy.special import smirnov
>>> from scipy.stats import norm
显示大小至少为 0、0.5 和 1.0 的间隙的概率,对于大小为 5 的样本。
>>> smirnov(5, [0, 0.5, 1.0])
array([ 1\. , 0.056, 0\. ])
比较大小为 5 的样本与 N(0, 1) 的标准正态分布,其中均值为 0,标准差为 1。
x 是样本。
>>> x = np.array([-1.392, -0.135, 0.114, 0.190, 1.82])
>>> target = norm(0, 1)
>>> cdfs = target.cdf(x)
>>> cdfs
array([0.0819612 , 0.44630594, 0.5453811 , 0.57534543, 0.9656205 ])
构造经验 CDF 和 K-S 统计量(Dn+、Dn-、Dn)。
>>> n = len(x)
>>> ecdfs = np.arange(n+1, dtype=float)/n
>>> cols = np.column_stack([x, ecdfs[1:], cdfs, cdfs - ecdfs[:n],
... ecdfs[1:] - cdfs])
>>> with np.printoptions(precision=3):
... print(cols)
[[-1.392 0.2 0.082 0.082 0.118]
[-0.135 0.4 0.446 0.246 -0.046]
[ 0.114 0.6 0.545 0.145 0.055]
[ 0.19 0.8 0.575 -0.025 0.225]
[ 1.82 1\. 0.966 0.166 0.034]]
>>> gaps = cols[:, -2:]
>>> Dnpm = np.max(gaps, axis=0)
>>> print(f'Dn-={Dnpm[0]:f}, Dn+={Dnpm[1]:f}')
Dn-=0.246306, Dn+=0.224655
>>> probs = smirnov(n, Dnpm)
>>> print(f'For a sample of size {n} drawn from N(0, 1):',
... f' Smirnov n={n}: Prob(Dn- >= {Dnpm[0]:f}) = {probs[0]:.4f}',
... f' Smirnov n={n}: Prob(Dn+ >= {Dnpm[1]:f}) = {probs[1]:.4f}',
... sep='\n')
For a sample of size 5 drawn from N(0, 1):
Smirnov n=5: Prob(Dn- >= 0.246306) = 0.4711
Smirnov n=5: Prob(Dn+ >= 0.224655) = 0.5245
绘制经验 CDF 和标准正态 CDF。
>>> import matplotlib.pyplot as plt
>>> plt.step(np.concatenate(([-2.5], x, [2.5])),
... np.concatenate((ecdfs, [1])),
... where='post', label='Empirical CDF')
>>> xx = np.linspace(-2.5, 2.5, 100)
>>> plt.plot(xx, target.cdf(xx), '--', label='CDF for N(0, 1)')
添加标记 Dn+ 和 Dn- 的垂直线。
>>> iminus, iplus = np.argmax(gaps, axis=0)
>>> plt.vlines([x[iminus]], ecdfs[iminus], cdfs[iminus], color='r',
... alpha=0.5, lw=4)
>>> plt.vlines([x[iplus]], cdfs[iplus], ecdfs[iplus+1], color='m',
... alpha=0.5, lw=4)
>>> plt.grid(True)
>>> plt.legend(framealpha=1, shadow=True)
>>> plt.show()
scipy.special.kolmogorov
scipy.special.kolmogorov(y, out=None) = <ufunc 'kolmogorov'>
Kolmogorov 分布的补充累积分布(Survival Function)函数。
返回两边检验(empirical 与 theoretical distribution 之间的)Kolmogorov 极限分布的补充累积分布函数(当 n 趋向无穷时,D_n*\sqrt(n))。等于(n 趋向无穷时的极限)概率,即sqrt(n) * max absolute deviation > y。
参数:
y 浮点数数组
经验累积分布函数(ECDF)与目标 CDF 之间的绝对偏差,乘以 sqrt(n)。
out ndarray,可选
函数结果的可选输出数组
返回值:
标量或 ndarray
kolmogorov(y)的值
另请参阅
kolmogi
分布的逆存活函数
scipy.stats.kstwobign
提供作为连续分布的功能
smirnov,smirnovi
一侧分布函数
注意事项
kolmogorov被stats.kstest在 Kolmogorov-Smirnov 拟合优度检验中使用。出于历史原因,此函数暴露在scipy.special中,但建议获取最精确的 CDF/SF/PDF/PPF/ISF 计算的方法是使用stats.kstwobign分布。
示例
显示至少大于 0、0.5 和 1.0 的间隙的概率。
>>> import numpy as np
>>> from scipy.special import kolmogorov
>>> from scipy.stats import kstwobign
>>> kolmogorov([0, 0.5, 1.0])
array([ 1\. , 0.96394524, 0.26999967])
将大小为 1000 的拉普拉斯(0, 1)分布样本与目标分布,正态(0, 1)分布进行比较。
>>> from scipy.stats import norm, laplace
>>> rng = np.random.default_rng()
>>> n = 1000
>>> lap01 = laplace(0, 1)
>>> x = np.sort(lap01.rvs(n, random_state=rng))
>>> np.mean(x), np.std(x)
(-0.05841730131499543, 1.3968109101997568)
构建经验累积分布函数(ECDF)和 K-S 统计量 Dn。
>>> target = norm(0,1) # Normal mean 0, stddev 1
>>> cdfs = target.cdf(x)
>>> ecdfs = np.arange(n+1, dtype=float)/n
>>> gaps = np.column_stack([cdfs - ecdfs[:n], ecdfs[1:] - cdfs])
>>> Dn = np.max(gaps)
>>> Kn = np.sqrt(n) * Dn
>>> print('Dn=%f, sqrt(n)*Dn=%f' % (Dn, Kn))
Dn=0.043363, sqrt(n)*Dn=1.371265
>>> print(chr(10).join(['For a sample of size n drawn from a N(0, 1) distribution:',
... ' the approximate Kolmogorov probability that sqrt(n)*Dn>=%f is %f' %
... (Kn, kolmogorov(Kn)),
... ' the approximate Kolmogorov probability that sqrt(n)*Dn<=%f is %f' %
... (Kn, kstwobign.cdf(Kn))]))
For a sample of size n drawn from a N(0, 1) distribution:
the approximate Kolmogorov probability that sqrt(n)*Dn>=1.371265 is 0.046533
the approximate Kolmogorov probability that sqrt(n)*Dn<=1.371265 is 0.953467
绘制经验累积分布函数(Empirical CDF)与目标 N(0, 1)累积分布函数的对比图。
>>> import matplotlib.pyplot as plt
>>> plt.step(np.concatenate([[-3], x]), ecdfs, where='post', label='Empirical CDF')
>>> x3 = np.linspace(-3, 3, 100)
>>> plt.plot(x3, target.cdf(x3), label='CDF for N(0, 1)')
>>> plt.ylim([0, 1]); plt.grid(True); plt.legend();
>>> # Add vertical lines marking Dn+ and Dn-
>>> iminus, iplus = np.argmax(gaps, axis=0)
>>> plt.vlines([x[iminus]], ecdfs[iminus], cdfs[iminus],
... color='r', linestyle='dashed', lw=4)
>>> plt.vlines([x[iplus]], cdfs[iplus], ecdfs[iplus+1],
... color='r', linestyle='dashed', lw=4)
>>> plt.show()
scipy.special.kolmogi
原文:
docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.kolmogi.html#scipy.special.kolmogi
scipy.special.kolmogi(p, out=None) = <ufunc 'kolmogi'>
Kolmogorov 分布的反生存函数
它是 kolmogorov 的反函数。返回 y 使得 kolmogorov(y) == p。
参数:
p 浮点数数组
概率
out 数组,可选
可选的输出数组用于函数结果
返回:
标量或者多维数组
kolmogi(p) 的值(或值)
另请参见
kolmogorov
分布的生存函数
scipy.stats.kstwobign
作为连续分布的功能
smirnov, smirnovi
单边分布的函数
注释
kolmogorov 被 stats.kstest 在 Kolmogorov-Smirnov 拟合优度检验中应用。由于历史原因,此函数在 scpy.special 中暴露,但实现最准确的 CDF/SF/PDF/PPF/ISF 计算的推荐方法是使用 stats.kstwobign 分布。
示例
>>> from scipy.special import kolmogi
>>> kolmogi([0, 0.1, 0.25, 0.5, 0.75, 0.9, 1.0])
array([ inf, 1.22384787, 1.01918472, 0.82757356, 0.67644769,
0.57117327, 0\. ])
scipy.special.boxcox
原文链接:
docs.scipy.org/doc/scipy-1.12.0/reference/generated/scipy.special.boxcox.html#scipy.special.boxcox
scipy.special.boxcox(x, lmbda, out=None) = <ufunc 'boxcox'>
计算 Box-Cox 变换。
Box-Cox 变换为:
y = (x**lmbda - 1) / lmbda if lmbda != 0
log(x) if lmbda == 0
如果 x < 0,返回 nan。如果 x == 0 且 lmbda < 0,返回 -inf。
参数:
xarray_like
待转换的数据。
lmbdaarray_like
Box-Cox 变换的功率参数。
outndarray,可选
可选的输出数组,用于存储函数值
返回:
y标量或者 ndarray
转换后的数据。
注释
新版本 0.14.0 中引入。
示例
>>> from scipy.special import boxcox
>>> boxcox([1, 4, 10], 2.5)
array([ 0\. , 12.4 , 126.09110641])
>>> boxcox(2, [0, 1, 2])
array([ 0.69314718, 1\. , 1.5 ])
scipy.special.boxcox1p
scipy.special.boxcox1p(x, lmbda, out=None) = <ufunc 'boxcox1p'>
计算 1 + x的 Box-Cox 变换。
由boxcox1p计算的 Box-Cox 变换为:
y = ((1+x)**lmbda - 1) / lmbda if lmbda != 0
log(1+x) if lmbda == 0
如果x < -1,则返回nan。如果x == -1且lmbda < 0,则返回*-inf*。
参数:
x array_like
要转换的数据。
lmbda array_like
Box-Cox 变换的功率参数。
out ndarray,可选
函数值的可选输出数组。
返回:
y scalar 或 ndarray
转换后的数据。
注意事项
0.14.0 版本中的新功能。
示例
>>> from scipy.special import boxcox1p
>>> boxcox1p(1e-4, [0, 0.5, 1])
array([ 9.99950003e-05, 9.99975001e-05, 1.00000000e-04])
>>> boxcox1p([0.01, 0.1], 0.25)
array([ 0.00996272, 0.09645476])
scipy.special.inv_boxcox
scipy.special.inv_boxcox(y, lmbda, out=None) = <ufunc 'inv_boxcox'>
计算 Box-Cox 变换的逆变换。
找到 x 使得:
y = (x**lmbda - 1) / lmbda if lmbda != 0
log(x) if lmbda == 0
参数:
y 数组类型
待转换的数据。
lmbda 数组类型
Box-Cox 变换的幂参数。
out ndarray,可选
可选的输出数组,用于函数值
返回值:
x 标量或者 ndarray
转换后的数据。
笔记
自版本 0.16.0 新增。
示例
>>> from scipy.special import boxcox, inv_boxcox
>>> y = boxcox([1, 4, 10], 2.5)
>>> inv_boxcox(y, 2.5)
array([1., 4., 10.])
scipy.special.inv_boxcox1p
scipy.special.inv_boxcox1p(y, lmbda, out=None) = <ufunc 'inv_boxcox1p'>
计算 Box-Cox 变换的逆变换。
找到 x 使得:
y = ((1+x)**lmbda - 1) / lmbda if lmbda != 0
log(1+x) if lmbda == 0
参数:
y array_like
待转换的数据。
lmbda array_like
Box-Cox 变换的功率参数。
out ndarray,可选
函数值的可选输出数组
返回:
x 标量或者 ndarray
转换后的数据。
注意事项
新版在 0.16.0 版本中加入。
示例
>>> from scipy.special import boxcox1p, inv_boxcox1p
>>> y = boxcox1p([1, 4, 10], 2.5)
>>> inv_boxcox1p(y, 2.5)
array([1., 4., 10.])