python - 使用两个不同大小的 pandas 数据框进行 Wilcoxon 测试
问题描述
我有两个不同长度的数据帧(一个是 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.
我在这篇文章中看到在R 上讨论这个问题,你可以通过传递 pair: FALSE 来做到这一点。通过这样做,它相当于进行 Mann-Whitney 检验。
有没有办法在 Python 上使用 scipy.stats.wilocoxon 做同样的事情,或者我应该直接使用scipy.stats.mannwhitneyu吗?
谢谢
解决方案
如果您想要非配对 wilcoxon 测试,mannwhitneyu 似乎是正确的选择。在 mannwhitneyu 的 scipy 文档中,您可以找到以下描述:mannwhitneyu is for independent samples. For related / paired samples, consider scipy.stats.wilcoxon.
推荐阅读
- firebase - 对于 Double Child 的值,安全规则的适当处理是什么?
- c# - 如何在运行时在 Unity 中导入字体
- android - Android 音频策略、定义的设备和默认路由
- python - Sqlalchemy 自引用多对多与关联代理和对象映射表
- flutter - Flutter GestureDector 用于拖动小部件:坐标与第二次拖动不匹配
- c# - SonarQube 找不到 Microsoft.CodeAnalysis 1.3.1.0 但已安装
- android - 如果我将这行代码 [final path = join(documentsDirectory.path, "item5.db");] 更改为 item6 或其他内容,它将成功运行
- css - sass/scss #{$value + s} in less
- python - 奇怪的虫子。For 循环代码适用于大多数值,但随后会附加 4 次特定值
- r - 从字符串中提取地方部门并将其转换为R中的国家名称