曼-惠特尼U檢驗Mann–Whitney U Test(python代碼實現)

機器學習,統計項目聯繫QQ:231469242

 

兩個配對樣本,均勻分佈,非正太分佈python

Wilcoxon signed-rank testgit

 

曼-惠特尼U檢驗Mann–Whitney Testgithub

兩個獨立樣本,均勻分佈,非正太分佈機器學習

兩組樣本量必須大於20ide

 

例子:A方案治療和B方案治療是否有顯著差別?a=0.05學習

 此例子簡單說明計算過程,但不許確,由於樣本數必須大於20this

 

參照使用Z分數表spa

 

 

若是Z分數小於-1.96或大於1.96,拒絕原假設3d

 

計算排名orm

一共12個數,排名從1-12,第一12,第十二36,第四名和第五名都是19

 

 

第四名和第五名都平均爲4.5

 

 

計算每一個score的points

B樣本的12,小於A的一個樣本得1分,都小於A的樣本,A的樣本是6,因此得6*1=6分

A樣本的28,小於B的一個樣本得1分,都大於A的樣本,A的樣本是6,因此得6*0=0分

 

UA,A樣本的全部points相加

UB,B樣本的全部Points相加

U值取UA和UB的最小值

 

計算Z分數,其公式如圖:

nA,nB 表示兩個樣本量

 

計算的Z值=-2.88,小於-1.96,拒絕原假設

 

 

 

                               
                               
                               
                               
                               
                               
                               
                               
                               
                               
                               
                               
                               
                               
                               
                               
                               

 

 

Nonparametric Comparison of Two Groups:
Mann–Whitney Test
If the measurement values from two groups are not normally distributed we have
to resort to a nonparametric test. The most common nonparametric test for the
comparison of two independent groups is the Mann–Whitney(–Wilcoxon) test.
Watch out, because this test is sometimes also referred to as Wilcoxon rank-sum
test. This is different from the Wilcoxon signed rank sum test! The test-statistic for
this test is commonly indicated with u:


u_statistic, pVal = stats.mannwhitneyu(group1, group2)

https://github.com/thomas-haslwanter/statsintro_python/tree/master/ISP/Code_Quantlets/08_Test
sMeanValues/twoGroups.


Code: 「ISP_twoGroups.py」3: Comparison of two groups, paired and unpaired.

 

 

 

舉例:

判斷兩組數是否有顯著差別,group1=[28,31,36,35,32,33,21,12,12,23,19,13,20,17,14,19] group2=[12,18,19,14,20,19,12,11,8,9,10,15,16,17,10,16]

# -*- coding: utf-8 -
'''
每組樣本量必須大於20
'''

import scipy.stats as stats

group1=[28,31,36,35,32,33,21,12,12,23,19,13,20,17,14,19]
group2=[12,18,19,14,20,19,12,11,8,9,10,15,16,17,10,16]


u_statistic, pVal = stats.mannwhitneyu(group1, group2)

'''
Out[2]: MannwhitneyuResult(statistic=46.5, pvalue=0.0011073479271168959)
p值小於0.05,兩組數據有顯著差別
'''
做者Toby,qq:231469242

 

p值小於0.05,有顯著差別,拒絕原假設,兩組數據有顯著差別

 

 https://study.163.com/provider/400000000398149/index.htm?share=2&shareId=400000000398149( 歡迎關注博主主頁,學習python視頻資源,還有大量免費python經典文章)

 

相關文章
相關標籤/搜索