2014-10-07 62 views
1

Mann-Witney-U-test與只能用於正態分佈數據的t檢驗等價。在SciPy的兩種測試是可用的:在指定的numpy座標軸上計算mannwhitneyu

t檢驗:http://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.ttest_ind.html

曼 - 惠特尼-U檢驗:http://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.stats.mannwhitneyu.html

雖然可以在一個例如可以計算t檢驗通過指定軸來執行計算的3D數組,這對Mann-Witney-U-test來說似乎不可行?

import numpy 
from scipy import stats 

A1= numpy.random.normal(1,1,50).reshape(25, 2) 
A2= numpy.random.normal(1,1,50).reshape(25, 2) 
A3= numpy.random.normal(1,1,50).reshape(25, 2) 
A4= numpy.random.normal(1,1,50).reshape(25, 2) 
A5= numpy.random.normal(1,1,50).reshape(25, 2) 
A = numpy.dstack((A1,A2,A3,A4,A5)) 

B1= numpy.random.normal(3,1,50).reshape(25, 2) 
B2= numpy.random.normal(3,1,50).reshape(25, 2) 
B3= numpy.random.normal(3,1,50).reshape(25, 2) 
B4= numpy.random.normal(3,1,50).reshape(25, 2) 
B5= numpy.random.normal(3,1,50).reshape(25, 2) 
B = numpy.dstack((B1,B2,B3,B4,B5)) 

ttest_result = stats.ttest_ind(A,B,axis=2) 

然而指定軸線曼 - 惠特尼-U-測試是不可能的(如stats.mannwhitneyu(A1,B1,axis=2)

是否有可能運行mannwhitneyu用於3D陣列的specifyed軸? 由於mannwhitneyu()需要兩個數組,因此numpy.apply_along_axis()也不能直接使用。有什麼建議麼?

回答

0

如果你想瓶坯在這個例子中的第3軸類似的操作,我認爲你可以做到以下幾點:

In [304]: 

result = map(stats.mannwhitneyu, A.reshape(-1, A.shape[2]),B.reshape(-1, B.shape[2])) 
u = np.array([item[0] for item in result]).reshape(A.shape[0], -1) 
p = np.array([item[1] for item in result]).reshape(A.shape[0], -1) 
In [305]: 

u 
Out[305]: 
array([[ 0., 4.], 
     ... 
     [ 1., 2.]]) 
In [306]: 

p 
Out[306]: 
array([[ 0.00609289, 0.04734647], 
     ... 
     [ 0.01078587, 0.01835693]])