Skip to main content

add statistical significance annotations on seaborn boxplot/barplot. Based on statannot 0.2.3

Project description

Active Development coverage Python

What is it

Python package to optionally compute statistical test and add statistical annotations on boxplots or barplots generated with seaborn.

Derived work

This repository is evolving independently from webermarcolivier/statannot by Marc Weber. It is based on commit 1835078 of Feb 21, 2020, tagged "v0.2.3".

Additions/modifications since that version are below represented in bold (previous fixes are not listed). New issues and PRs are welcome and will be looked into.

The statannot interface, at least until its version 0.2.3, is directly usable in statannotations, which provides additional features.

Features

  • Single function to add statistical annotations on an existing boxplot/barplot generated by seaborn boxplot.
  • Integrated statistical tests (binding to scipy.stats methods):
    • Mann-Whitney
    • t-test (independent and paired)
    • Welch's t-test
    • Levene test
    • Wilcoxon test
    • Kruskal-Wallis test
  • Interface to use any other function from any source with minimal extra code
  • Smart layout of multiple annotations with correct y offsets.
  • Annotations can be located inside or outside the plot.
  • Corrections for multiple testing can be applied (binding to statsmodels.stats.multitest.multipletests methods):
    • Bonferroni
    • Holm-Bonferroni
    • Benjamini-Hochberg
    • Benjamini-Yekutieli
  • And any other function from any source with minimal extra code
  • Format of the statistical test annotation can be customized: star annotation, simplified p-value, or explicit p-value.
  • Optionally, custom p-values can be given as input. In this case, no statistical test is performed, but corrections for multiple testing can be applied.
  • And various fixes (see CHANGELOG.md).

Installation

From version 0.3.0 on, the package is distributed on PyPi.
The latest stable release can be downloaded and installed with:

pip install statannotations

or, after cloning the repository,

pip install -r requirements.txt .

Documentation

See example jupyter notebook doc/example.ipynb.

Usage

Here is a minimal example:

import seaborn as sns
from statannotations import add_stat_annotation

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)
add_stat_annotation(
    ax, data=df, x=x, y=y, order=order,
    box_pairs=[("Thur", "Fri"), ("Thur", "Sat"), ("Fri", "Sun")],
    test='Mann-Whitney', text_format='star', loc='outside', verbose=2)

Examples

Example 1

Example 2

Requirements

  • Python >= 3.6
  • numpy >= 1.12.1
  • seaborn >= 0.9
  • matplotlib >= 2.2.2
  • pandas >= 0.23.0
  • scipy >= 1.1.0
  • statsmodels (optional, for multiple testing corrections)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

statannotations-0.3.1.tar.gz (17.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

statannotations-0.3.1-py3-none-any.whl (19.9 kB view details)

Uploaded Python 3

File details

Details for the file statannotations-0.3.1.tar.gz.

File metadata

  • Download URL: statannotations-0.3.1.tar.gz
  • Upload date:
  • Size: 17.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.23.0 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.7.0

File hashes

Hashes for statannotations-0.3.1.tar.gz
Algorithm Hash digest
SHA256 b8e334dbd58efc94068290c95ad61e2f3ed707f4a7369e48ee784e2fc2cf5372
MD5 b962894d4d890c6b7981caa8d6c67a4e
BLAKE2b-256 82d7d58e8db2df9b7c76c2a44b16b720ed2104c798987d9022bd8d4cf464a7bb

See more details on using hashes here.

File details

Details for the file statannotations-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: statannotations-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 19.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.23.0 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.7.0

File hashes

Hashes for statannotations-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b380b7e5e97391e7de02031769b2956fa38390ed466c0d50192ef3ef5aae566a
MD5 5c494d663c31a5a7e3082e14bb8ec876
BLAKE2b-256 1dc92cc8ce2b1c9df43b8fbaf8acbb7ffdd456c7bb1603df861c98d761904bd3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page