Skip to content

Latest commit

 

History

History
65 lines (46 loc) · 1.56 KB

File metadata and controls

65 lines (46 loc) · 1.56 KB

pairwise-test-python

pairwise-test-python provides simple helper functions for running pairwise statistical tests on categorical data stored in a pandas DataFrame.

The package currently includes:

  • chisquare(): pairwise chi-square tests across all combinations of a fixed grouping variable
  • fisher(): pairwise Fisher's exact tests across all combinations of a fixed grouping variable

Both functions return the raw p-value and a Bonferroni-corrected p-value based on the total number of pairwise tests performed.

Requirements

  • pandas
  • scipy

Usage

import pandas as pd
from pairwise import chisquare, fisher

df = pd.DataFrame(
    {
        "Group": ["A", "A", "B", "B", "C", "C", "A", "B", "C"],
        "Sex": ["M", "F", "M", "F", "M", "F", "M", "M", "F"],
    }
)

chi2_results = chisquare(df, "Group", "Sex")
fisher_results = fisher(df, "Group", "Sex")

print(chi2_results)
print(fisher_results)

Returned DataFrame

Each function returns a pandas DataFrame with these columns:

  • Variable1
  • Variable2
  • p-value
  • bonferroni p-value

The Bonferroni-corrected p-value is computed as:

min(p_value * number_of_tests, 1.0)

where number_of_tests is the number of pairwise comparisons generated from the unique values in the fixed variable column.

Notes

  • col1 should be the fixed grouping variable.
  • col2 should be the categorical outcome variable.
  • The functions also print the result of each pairwise comparison to the console.
  • Use help(chisquare) or help(fisher) for function-level documentation.