# 統計檢定套件: statannotations ###### tags: `求生指引` [Github](https://github.com/trevismd/statannotations) [TOC] ## 使用方式+星號更改 ``` .py annot = Annotator(ax, box_pairs, data=df, x="Method", y="R$^2$",) annot.configure(test=test_med[choose_med], text_format='star', loc='outside', verbose=False, pvalue_thresholds=[[1e-3, "***"], [1e-2, "**"], [0.05, "*"], [1, "ns"]]) annot.apply_test().annotate() ``` ## 統計檢定方法 ### 預設 * Mann-Whitney * 'Mann-Whitney' (=stats.mannwhitneyu, alternative='two-sided') * 'Mann-Whitney-gt' (=stats.mannwhitneyu, alternative='greater')(no same length) * 'Mann-Whitney-ls' (=stats.mannwhitneyu, alternative='less')(no same length) * t-test * t-test_ind (=stats.ttest_ind) * t-test_paired (=stats.ttest_rel) * t-test_welch (=stats.ttest_ind, equal_var=False) * Levene test * 'Levene' (=stats.levene) * Wilcoxon test * 'Wilcoxon' (=stats.wilcoxon) * Kruskal-Wallis test * 'Kruskal' (=stats.kruskal) * Brunner-Munzel test * 'Brunner-Munzel' (=stats.brunnermunzel) ![](https://i.imgur.com/rijOqjB.png) ### 新增其他 scipy.stats 中的方法 * statannotations/stats/StatTest.py 搜尋 STATTEST_LIBRARY (line.88) * 在 STATTEST_LIBRARY 中新增方法 → '使用時輸入的字串': StatTest(scipy.stats的方法, test_long_name(不重要), test_short_name(不重要), stat_name(不重要), 其他scipy.stats可設定的參數 ) 例如: ``` 'My-test': StatTest(stats.ranksums, 'Wilcoxon rank-sum statistic for two samples', 'rank-sum') ``` * statannotations/stats/test.py 搜尋 IMPLEMENTED_TESTS (line.10) * 在 IMPLEMENTED_TESTS 中新增前述步驟加入的方法字串 例如: ``` IMPLEMENTED_TESTS = ['t-test_ind', 't-test_welch', 't-test_paired', 'Mann-Whitney', 'Mann-Whitney-gt', 'Mann-Whitney-ls', 'Levene', 'Wilcoxon', 'Kruskal', 'Brunner-Munzel', 'My-test'] ``` * 完成