Python-spearman相关系数不匹配。

2024-04-19 13:49:04 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我有一个数据集,它是分子丰度,作为物理参数的函数,我想确定两者之间的相关性。这两个参数跨越数个数量级。在

因为两者不是线性相关的,所以我选择使用scipy.stats.spearmanr中的Spearman秩相关系数。但我的问题是,结果有时毫无意义,我不知道我做错了什么。在

下图显示了丰度的三种不同时间(颜色)。但令人好奇的是,尽管黑线显示出丰度的下降,因此呈负相关系数,但另外两条线却显示出正相关,尽管它们与黑线的差别不大! The example figure

这是我使用的代码,我排除了代码的外观部分。在

for t in range(0, len(times)):
    ax.loglog(parameter, abunds[t], color=colors[t])
    corr_coeffs[t] = stats.spearmanr(np.log10(parameter),np.log10(abundances[t,:])
    patches.append(mpatches.Patch(color=colors[t], label="r=" + str(("%.2f"%corr_coeffs[t,0])) + ", p=" + str(("%.2f"%corr_coeffs[t,1])) + " | " + time_label[t]))
legend  =   plt.legend(handles=patches, fontsize="large", loc='best')
plt.savefig('example.png')

如果有人能向我解释这种奇怪的行为,我将不胜感激。在


Tags: 代码参数parameterstatsnplabelcolorcolors