本文簡要介紹 python 語言中 scipy.stats.anderson_ksamp
的用法。
用法:
scipy.stats.anderson_ksamp(samples, midrank=True, *, method=None)#
Anderson-Darling 測試k-samples。
k-sample Anderson-Darling 測試是單樣本 Anderson-Darling 測試的一種修改。它測試 k-samples 來自同一總體的原假設,而無需指定該總體的分布函數。臨界值取決於樣本數量。
- samples: 一維 數組 序列
數組中的樣本數據數組。
- midrank: 布爾型,可選
計算的Anderson-Darling 測試的類型。默認 (True) 是適用於連續和離散總體的中秩檢驗。如果為 False,則使用右側經驗分布。
- method: 排列方法,可選
定義用於計算 p 值的方法。如果方法是一個實例
PermutationMethod
,p 值的計算方法為scipy.stats.permutation_test使用提供的配置選項和其他適當的設置。否則,p 值是根據表格值插值得出的。
- res: Anderson_ksampResult
包含屬性的對象:
- 統計 浮點數
標準化 k-sample Anderson-Darling 測試統計量。
- critical_values 數組
顯著性水平的臨界值 25%、10%、5%、2.5%、1%、0.5%、0.1%。
- p值 浮點數
檢驗的近似 p 值。如果未提供方法,則該值的下限/上限為 0.1%/25%。
- ValueError
如果提供的樣本少於 2 個,則樣本為空,或者樣本中沒有明顯的觀察結果。
參數 ::
返回 ::
拋出 ::
注意:
[1] 定義了 k-sample Anderson-Darling 測試的三個版本:一個用於連續分布,兩個用於離散分布,其中樣本之間可能發生聯係。此例程的默認設置是根據中秩經驗分布函數計算版本。該測試適用於連續和離散數據。如果 midrank 設置為 False,則右側經驗分布用於離散數據的測試。根據 [1],如果在未針對樣本之間的聯係進行調整的測試中發生由於舍入誤差導致的一些衝突,則兩個離散測試統計量僅略有不同。
與 0.01 到 0.25 之間的顯著性水平相對應的臨界值取自 [1]。 p 值的下限/上限為 0.1%/25%。由於未來版本中可能會擴展臨界值的範圍,因此建議不要測試
p == 0.25
,而是測試p >= 0.25
(與下限類似)。參考:
[1] (1,2,3)Scholz, F. W 和 Stephens, M. A. (1987),K-Sample Anderson-Darling 測試,美國統計協會雜誌,卷。 82,第 918-924 頁。
例子:
>>> import numpy as np >>> from scipy import stats >>> rng = np.random.default_rng() >>> res = stats.anderson_ksamp([rng.normal(size=50), ... rng.normal(loc=0.5, size=30)]) >>> res.statistic, res.pvalue (1.974403288713695, 0.04991293614572478) >>> res.critical_values array([0.325, 1.226, 1.961, 2.718, 3.752, 4.592, 6.546])
兩個隨機樣本來自相同分布的原假設可以在 5% 的水平上被拒絕,因為返回的檢驗值大於 5% 的臨界值 (1.961),但在 2.5% 的水平上則不然。插值得出的近似 p 值為 4.99%。
>>> samples = [rng.normal(size=50), rng.normal(size=30), ... rng.normal(size=20)] >>> res = stats.anderson_ksamp(samples) >>> res.statistic, res.pvalue (-0.29103725200789504, 0.25) >>> res.critical_values array([ 0.44925884, 1.3052767 , 1.9434184 , 2.57696569, 3.41634856, 4.07210043, 5.56419101])
對於來自相同分布的三個樣本,不能拒絕原假設。報告的 p 值 (25%) 已設定上限,可能不太準確(因為它對應於值 0.449,而統計量為 -0.291)。
在 p 值有上限或樣本量較小的情況下,排列檢驗可能更準確。
>>> method = stats.PermutationMethod(n_resamples=9999, random_state=rng) >>> res = stats.anderson_ksamp(samples, method=method) >>> res.pvalue 0.5254
相關用法
- Python SciPy stats.anderson用法及代碼示例
- Python SciPy stats.anglit用法及代碼示例
- Python SciPy stats.ansari用法及代碼示例
- Python SciPy stats.alexandergovern用法及代碼示例
- Python SciPy stats.arcsine用法及代碼示例
- Python SciPy stats.argus用法及代碼示例
- Python SciPy stats.alpha用法及代碼示例
- Python SciPy stats.iqr用法及代碼示例
- Python SciPy stats.genpareto用法及代碼示例
- Python SciPy stats.skewnorm用法及代碼示例
- Python SciPy stats.cosine用法及代碼示例
- Python SciPy stats.norminvgauss用法及代碼示例
- Python SciPy stats.directional_stats用法及代碼示例
- Python SciPy stats.invwishart用法及代碼示例
- Python SciPy stats.bartlett用法及代碼示例
- Python SciPy stats.levy_stable用法及代碼示例
- Python SciPy stats.page_trend_test用法及代碼示例
- Python SciPy stats.itemfreq用法及代碼示例
- Python SciPy stats.exponpow用法及代碼示例
- Python SciPy stats.gumbel_l用法及代碼示例
- Python SciPy stats.chisquare用法及代碼示例
- Python SciPy stats.semicircular用法及代碼示例
- Python SciPy stats.gzscore用法及代碼示例
- Python SciPy stats.gompertz用法及代碼示例
- Python SciPy stats.normaltest用法及代碼示例
注:本文由純淨天空篩選整理自scipy.org大神的英文原創作品 scipy.stats.anderson_ksamp。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。