scipy.special.fdtr#

scipy.special.fdtr(dfn, dfd, x, out=None) = <ufunc 'fdtr'>#

F 累積分布函數。

傳回 F 分布的累積分布函數值,也稱為 Snedecor's F 分布或 Fisher-Snedecor 分布。

具有參數 \(d_n\)\(d_d\) 的 F 分布是隨機變數的分布,

\[X = \frac{U_n/d_n}{U_d/d_d},\]

其中 \(U_n\)\(U_d\) 是服從 \(\chi^2\) 分布的隨機變數,分別具有 \(d_n\)\(d_d\) 個自由度。

參數:
dfnarray_like

第一個參數(正浮點數)。

dfdarray_like

第二個參數(正浮點數)。

xarray_like

引數(非負浮點數)。

outndarray, optional

函數值的選用輸出陣列

傳回值:
y純量或 ndarray

x 處,具有參數 dfndfd 的 F 分布 CDF。

另請參閱

fdtrc

F 分布存活函數

fdtri

F 分布反累積分布

scipy.stats.f

F 分布

註解

正規化不完全貝塔函數用於此,根據公式,

\[F(d_n, d_d; x) = I_{xd_n/(d_d + xd_n)}(d_n/2, d_d/2).\]

Cephes [1] 常式 fdtr 的包裝函式。F 分布也可用作 scipy.stats.f。直接呼叫 fdtr 可以比呼叫 scipy.stats.fcdf 方法提高效能(請參閱下面的最後一個範例)。

參考文獻

[1]

Cephes Mathematical Functions Library, http://www.netlib.org/cephes/

範例

計算 dfn=1dfd=2x=1 時的函數值。

>>> import numpy as np
>>> from scipy.special import fdtr
>>> fdtr(1, 2, 1)
0.5773502691896258

透過為 x 提供 NumPy 陣列來計算多個點的函數值。

>>> x = np.array([0.5, 2., 3.])
>>> fdtr(1, 2, x)
array([0.4472136 , 0.70710678, 0.77459667])

繪製多組參數的函數圖。

>>> import matplotlib.pyplot as plt
>>> dfn_parameters = [1, 5, 10, 50]
>>> dfd_parameters = [1, 1, 2, 3]
>>> linestyles = ['solid', 'dashed', 'dotted', 'dashdot']
>>> parameters_list = list(zip(dfn_parameters, dfd_parameters,
...                            linestyles))
>>> x = np.linspace(0, 30, 1000)
>>> fig, ax = plt.subplots()
>>> for parameter_set in parameters_list:
...     dfn, dfd, style = parameter_set
...     fdtr_vals = fdtr(dfn, dfd, x)
...     ax.plot(x, fdtr_vals, label=rf"$d_n={dfn},\, d_d={dfd}$",
...             ls=style)
>>> ax.legend()
>>> ax.set_xlabel("$x$")
>>> ax.set_title("F distribution cumulative distribution function")
>>> plt.show()
../../_images/scipy-special-fdtr-1_00_00.png

F 分布也可用作 scipy.stats.f。直接使用 fdtr 可能比呼叫 scipy.stats.fcdf 方法快得多,尤其對於小陣列或個別值。為了獲得相同的結果,必須使用以下參數化:stats.f(dfn, dfd).cdf(x)=fdtr(dfn, dfd, x)

>>> from scipy.stats import f
>>> dfn, dfd = 1, 2
>>> x = 1
>>> fdtr_res = fdtr(dfn, dfd, x)  # this will often be faster than below
>>> f_dist_res = f(dfn, dfd).cdf(x)
>>> fdtr_res == f_dist_res  # test that results are equal
True