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

积分的上界

ndarray,可选

函数结果的可选输出数组

返回:
标量或ndarray

学生 t 分布累积分布函数在 t 处的值

参见

stdtridf

关于 df 的 stdtr 的逆

stdtrit

关于 t 的 stdtr 的逆

scipy.stats.t

学生 t 分布

注释

学生 t 分布也可以通过 scipy.stats.t 获得。直接调用 stdtr 可以提高性能,相比于 scipy.stats.tcdf 方法(见下面的最后一个例子)。

示例

计算 df=3t=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()
../../_images/scipy-special-stdtr-1_00_00.png

通过为 df 提供一个 NumPy 数组或列表,该函数可以同时计算多个自由度的值:

>>> stdtr([1, 2, 3], 1)
array([0.75      , 0.78867513, 0.80449889])

通过为 dft 提供形状兼容广播的数组,可以同时在多个点上计算多个不同自由度的函数。计算 stdtr 在 4 个点上对于 3 个自由度的结果,得到一个形状为 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.tcdf 方法要快得多。要获得相同的结果,必须使用以下参数化: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