本文簡要介紹 python 語言中 scipy.special.fdtr
的用法。
用法:
scipy.special.fdtr(dfn, dfd, x, out=None) = <ufunc 'fdtr'>#
F累積分布函數。
返回 F-distribution 的累積分布函數的值,也稱為 Snedecor 的 F-distribution 或 Fisher-Snedecor 分布。
帶有參數 和 的F-distribution是隨機變量的分布,
其中 和 是隨機變量分布 ,分別具有 和 自由度。
- dfn: array_like
第一個參數(正浮點數)。
- dfd: array_like
第二個參數(正浮點數)。
- x: array_like
參數(非負浮點數)。
- out: ndarray,可選
函數值的可選輸出數組
- y: 標量或 ndarray
F-distribution 的 CDF,參數 dfn 和 dfd 在 x 處。
參數 ::
返回 ::
注意:
采用正則化不完全beta函數,根據公式,
Cephes [1] 例程的包裝器
fdtr
。 F 分布也可用作scipy.stats.f
。與scipy.stats.f
的cdf
方法相比,直接調用fdtr
可以提高性能(請參見下麵的最後一個示例)。參考:
[1]Cephes 數學函數庫,http://www.netlib.org/cephes/
例子:
計算
x=1
處的dfn=1
和dfd=2
的函數。>>> 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()
F 分布也可用作
scipy.stats.f
。直接使用fdtr
比調用scipy.stats.f
的cdf
方法要快得多,特別是對於小型數組或單個值。為了獲得相同的結果,必須使用以下參數化: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
相關用法
- Python SciPy special.fdtridfd用法及代碼示例
- Python SciPy special.fdtrc用法及代碼示例
- Python SciPy special.fdtri用法及代碼示例
- Python SciPy special.factorial用法及代碼示例
- Python SciPy special.fresnel用法及代碼示例
- Python SciPy special.factorial2用法及代碼示例
- Python SciPy special.factorialk用法及代碼示例
- Python SciPy special.exp1用法及代碼示例
- Python SciPy special.expn用法及代碼示例
- Python SciPy special.ncfdtri用法及代碼示例
- Python SciPy special.gamma用法及代碼示例
- Python SciPy special.y1用法及代碼示例
- Python SciPy special.y0用法及代碼示例
- Python SciPy special.ellip_harm_2用法及代碼示例
- Python SciPy special.i1e用法及代碼示例
- Python SciPy special.smirnovi用法及代碼示例
- Python SciPy special.ker用法及代碼示例
- Python SciPy special.ynp_zeros用法及代碼示例
- Python SciPy special.k0e用法及代碼示例
- Python SciPy special.j1用法及代碼示例
- Python SciPy special.logsumexp用法及代碼示例
- Python SciPy special.expit用法及代碼示例
- Python SciPy special.polygamma用法及代碼示例
- Python SciPy special.nbdtrik用法及代碼示例
- Python SciPy special.nbdtrin用法及代碼示例
注:本文由純淨天空篩選整理自scipy.org大神的英文原創作品 scipy.special.fdtr。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。