简体   繁体   English

使用两个不同大小的熊猫数据框进行 Wilcoxon 测试

[英]Wilcoxon test with two pandas dataframe of different sizes

I have two dataframe of different length (one is 16 and the other 28).我有两个不同长度的数据帧(一个是 16,另一个是 28)。 I want to do a Wilcoxon test between those two using scipy.stats.wilcoxon .我想使用scipy.stats.wilcoxon在这两者之间进行 Wilcoxon 测试。 For this I have created a function:为此,我创建了一个函数:

def wilcoxon_test(df1, df2):

  list_col_1 = df1.columns
  list_col_2 = df2.columns

  for i in range(0, len(list_col_1)):
    name = list_col_1[i]
    for j in range(0, len(list_col_2)):
      name_check = list_col_2[j]
      if name_check == name:
        stat, pvalue = stats.wilcoxon(df1[name], df2[name_check])
        print("Wilcoxon test of {} and {}: stat = {}, pvalue = {}".format(name,name_check,stat,pvalue))
        if pvalue < 0.01:
          print("Pvalue between {} and {} < 0.01".format(name,name_check))

  return None

It works well when data have the same size, but I am working with DataFrames of different size, and it gives me this error: ValueError: The samples x and y must have the same length.当数据具有相同大小时它运行良好,但我正在使用不同大小的数据帧,它给了我这个错误: ValueError: The samples x and y must have the same length.

I've seen on this post discussing this issue on R, that you can do it by passing paired: FALSE.我在这篇文章中看到在 R 上讨论这个问题,你可以通过传递 paired: FALSE 来做到这一点。 By doing this, it's equivalent to doing a Mann-Whitney test.通过这样做,它相当于进行了 Mann-Whitney 检验。

It's there a way to do the same on Python with scipy.stats.wilocoxon or should I directly use scipy.stats.mannwhitneyu ?有没有办法用 scipy.stats.wilocoxon 在 Python 上做同样的事情,还是我应该直接使用scipy.stats.mannwhitneyu

Thanks谢谢

if you want a non paired wilcoxon test, mannwhitneyu seems to be the right choice.如果你想要一个非配对的威尔科克森测试,mannwhitneyu 似乎是正确的选择。 In scipy documentation on mannwhitneyu you can find the following description : mannwhitneyu is for independent samples. For related / paired samples, consider scipy.stats.wilcoxon.在 mannwhitneyu 的 scipy 文档中,您可以找到以下描述: mannwhitneyu is for independent samples. For related / paired samples, consider scipy.stats.wilcoxon. mannwhitneyu is for independent samples. For related / paired samples, consider scipy.stats.wilcoxon.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM