python金融風控評分卡模型和數據分析微專業課(博主親自錄制視頻):http://dwz.date/b9vv
機器學習,統計項目聯系QQ:231469242
兩個配對樣本,均勻分布,非正太分布
Wilcoxon signed-rank test
曼-惠特尼U檢驗Mann–Whitney Test
兩個獨立樣本,均勻分布,非正太分布
兩組樣本量必須大於20
例子:A方案治療和B方案治療是否有顯著差異?a=0.05
此例子簡單說明計算過程,但不准確,因為樣本數必須大於20
參照使用Z分數表
如果Z分數小於-1.96或大於1.96,拒絕原假設
計算排名
一共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,有顯著差異,拒絕原假設,兩組數據有顯著差異