微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Python,seaborn,使用statannot的统计分析看起来不对

如何解决Python,seaborn,使用statannot的统计分析看起来不对

我使用 statannot 对一些基本数据进行了统计检验,但统计检验的结果似乎不正确。 IE。我的一些比较得出“P_val=0.000e+00 U_stat=0.000e+00”,我认为这是不可能的。我的数据框和/或代码有问题吗?

这是我使用的数据框:

DataFrame

这是我的代码

import pandas as pd
from matplotlib import pyplot as plt
import seaborn as sns
from statannot import add_stat_annotation
import scipy.stats as sp

data = pd.read_excel('Z:/DMF/GROUPS/gr_Veening/Users/Vik/scRNA-seq/FACSAria/Adherence-invasion assays/adherence_invasion_assay_a549-RFP 4-6-21.xlsx',sheet_name="Sheet2",header = 0)

sns.set_theme(style="darkgrid")
ax1 = sns.Boxplot(x="Strain",y="adherence_counts",data=data)
x = "Strain"
y = "adherence_counts"
order = ["D39","D39 Δcps","19F","19F ΔcomCDE"]
ax1 = sns.Boxplot(data=data,x=x,y=y,order=order)
plt.title("Adherence Assay")
plt.ylabel('CFU/ml')
plt.xlabel('')
ax1.set(xticklabels=["D39","D39 Δ$\it{cps}$","19F Δ$\it{comCDE}$"])
add_stat_annotation(ax1,data=data,order=order,Box_pairs=[("D39","19F"),("D39","D39 Δcps"),("D39 Δcps",("19F","19F ΔcomCDE")],test='Mann-Whitney',text_format='star',loc='inside',verbose=2)

最后,这是统计测试的结果:

D39 v.s. D39 Δcps: Mann-Whitney-Wilcoxon test two-sided with Bonferroni correction,P_val=0.000e+00 U_stat=0.000e+00
D39 Δcps v.s. 19F: Mann-Whitney-Wilcoxon test two-sided with Bonferroni correction,P_val=1.000e+00 U_stat=2.000e+00
19F v.s. 19F ΔcomCDE: Mann-Whitney-Wilcoxon test two-sided with Bonferroni correction,P_val=7.617e-01 U_stat=8.000e+00
D39 v.s. 19F: Mann-Whitney-Wilcoxon test two-sided with Bonferroni correction,P_val=0.000e+00 U_stat=0.000e+00
C:\Users\Vik\anaconda3\lib\site-packages\scipy\stats\stats.py:7171: RuntimeWarning: divide by zero encountered in double_scalars
  z = (bigu - meanrank) / sd

任何帮助将不胜感激,谢谢!

解决方法

您的问题来自两部分:

  • 从统计上讲,在您的某些情况下(例如“D39”与“19F”),一组中的所有项目都比另一组更大/更小,因此 0 U 统计量和极端 p 值。很有可能得到这些结果。它来自仅检查所提供值的等级(此测试的作用),它具有优点和局限性(+ Mann-Whitney 的测试也不适用于如此小的样本量,尤其是在 scipy 假设等变的情况下)。

  • 现在这行 z = (bigu - meanrank) / sd 失败意味着 np.sqrt(T * n1 * n2 * (n1+n2+1) / 12.0) = 0,所以在这种情况下 n1 和/或 n20,(它们是 len(x)len(y))。 source in scipy 所以,

    • statannot 中有一个错误,因为如果 orderbox_pair 都引用数据帧中不存在的序列,则这可能会悄悄发生我会在 statannotations 中更正。那谢谢你。

    • 但是,我无法使用您的数据框副本重现您的警告。 如果这是唯一的错误,您应该会在您向我们展示的地方看到图中缺少一个框。
      如果没有,是否有可能您更新了一些代码但没有在这里复制最后的输出?否则,可能会有更多发现,请告诉我们。

编辑:正如在讨论中发现的那样,如果 statannotorder 和数据集中的标签之间存在不匹配,则第二个问题可能发生在 box_pairs 中。这已在 statannotations 中修补,statannot 的一个分支。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。