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^2/df)^{-(df+1)/2}\, dx\]- 参数:
- dfarray_like
自由度
- tarray_like
积分上限
- outndarray, optional
用于存储函数结果的可选输出数组
- 返回:
- 标量或 ndarray
在 t 处的学生t CDF 值
另请参阅
stdtridf关于 df 的 stdtr 的反函数
stdtrit关于 t 的 stdtr 的反函数
scipy.stats.t学生t分布
附注
学生t分布也可作为
scipy.stats.t使用。直接调用stdtr与调用scipy.stats.t的cdf方法相比,可以提高性能(见下文最后一个示例)。该函数使用 Boost Math 库 [1] 计算,该库依赖于不完全贝塔函数。
数组 API 标准支持
stdtr对 NumPy 之外的 Python Array API 标准兼容后端具有实验性支持。请考虑通过设置环境变量SCIPY_ARRAY_API=1并提供 CuPy、PyTorch、JAX 或 Dask 数组作为数组参数来测试这些功能。支持以下后端和设备(或其他功能)的组合。库
CPU
GPU
NumPy
✅
不适用
CuPy
不适用
✅
PyTorch
✅
⛔
JAX
✅
✅
Dask
✅
不适用
有关更多信息,请参阅 对数组 API 标准的支持。
参考文献
[1]Boost C++ 库,https://boost.ac.cn/
示例
为
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 个自由度计算
stdtr在 4 个点处的结果,得到一个形状为 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