Python-statannotations库添加显著性标注:
1、官网资料:https://github.com/trevismd/statannotations
官网例子:
import seaborn as sns
from statannotations.Annotator import Annotator
df = sns.load_dataset("tips")
x = "day"
y = "total_bill"
order = ['Sun', 'Thur', 'Fri', 'Sat']
ax = sns.boxplot(data=df, x=x, y=y, order=order)
pairs=[("Thur", "Fri"), ("Thur", "Sat"), ("Fri", "Sun")]
annotator = Annotator(ax, pairs, data=df, x=x, y=y, order=order)
annotator.configure(test='Mann-Whitney', text_format='star', loc='outside')
annotator.apply_and_annotate()
结果:
更多例子参考:
https://github.com/trevismd/statannotations/blob/master/usage/example.ipynb
2、具体实现过程【关键代码】:
from statannotations.Annotator import Annotator
#绘制显著性+星号
pairs_width=[(1, 2), (2, 3)]
annotator_width = Annotator(ax3, pairs_width, data=df, x='class', y='y', order=[1, 2, 3])
annotator_width.configure(test='Mann-Whitney', text_format='star',line_height=0.00001,line_width=0.5,fontsize=6)
annotator_width.apply_and_annotate()
3、属性设置
annotator_width.configure(test='Mann-Whitney', text_format='star',line_height=0.00001,line_width=0.5,fontsize=6)
annotator_width.apply_test().annotate(line_offset_to_group=0.2, line_offset=0.1)
4、检测方法
- Mann-Whitney
- t-test (independent and paired)
- Welch’s t-test
- Levene test
- Wilcoxon test
- Kruskal-Wallis test
- Brunner-Munzel test