【发布时间】:2014-12-01 14:06:28
【问题描述】:
Mann-Witney-U 检验是 t 检验的非参数等效方法,只能用于正态分布数据。在 Scipy 中,两个测试都可用:
t 检验:http://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.ttest_ind.html
Mann-Witney-U 测试:http://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.stats.mannwhitneyu.html
虽然 ttest 可以通过例如通过指定轴来执行计算的 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)
但是,无法为 Mann-Witney-U 测试指定轴(如 stats.mannwhitneyu(A1,B1,axis=2))
是否有可能为 3D 数组的指定轴运行 mannwhitneyu? 由于 mannwhitneyu() 需要两个数组,因此 numpy.apply_along_axis() 也不能直接使用。有什么建议?
【问题讨论】:
标签: python arrays numpy statistics scipy