【问题标题】:Wilcoxon test with two pandas dataframe of different sizes使用两个不同大小的 pandas 数据框进行 Wilcoxon 测试
【发布时间】:2021-09-29 21:54:08
【问题描述】:

我有两个不同长度的数据帧(一个是 16,另一个是 28)。我想使用scipy.stats.wilcoxon 在这两者之间进行 Wilcoxon 测试。 为此,我创建了一个函数:

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

当数据大小相同时效果很好,但我正在使用不同大小的 DataFrame,它给了我这个错误:ValueError: The samples x and y must have the same length.

我在post 上看到在 R 上讨论这个问题,你可以通过传递 pair: FALSE 来做到这一点。通过这样做,它相当于进行 Mann-Whitney 检验。

有没有办法在 Python 上使用 scipy.stats.wilocoxon 做同样的事情,或者我应该直接使用 scipy.stats.mannwhitneyu 吗?

谢谢

【问题讨论】:

    标签: python pandas scipy


    【解决方案1】:

    如果您想要非配对 wilcoxon 测试,mannwhitneyu 似乎是正确的选择。在 mannwhitneyu 的 scipy 文档中,您可以找到以下描述:mannwhitneyu is for independent samples. For related / paired samples, consider scipy.stats.wilcoxon.

    【讨论】:

      猜你喜欢
      • 2018-03-21
      • 2020-09-13
      • 1970-01-01
      • 2019-09-22
      • 1970-01-01
      • 1970-01-01
      • 2020-06-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多