Fisher exact test - mauriceling/mauriceling.github.io GitHub Wiki

Purpose: To test whether 2 categorical variables (defining the rows and columns) are independent in 2x2 contingency table.

Null hypothesis: There is no relationship between between the 2 categorical variables; that is, the 2 categorical variables are not independent.

Alternate hypothesis: There is a relationship between the 2 categorical variables; that is, the 2 categorical variables are not independent.

Note:

  1. Fisher exact test is commonly used in place of Chi-square test of independence in event of small sample size.
  2. Barnard exact test and Boschloo’s exact test are more robust than Fisher exact test.

Code:

>>> from scipy import stats
>>> table = [[77, 404],
...          [16, 122]]
>>> result = stats.fisher_exact(table)
>>> print("Odds ratio = %.3f" % result[0])
Odds ratio = 1.453
>>> print("p-value = %.3f" % result[1])
p-value = 0.225

Reference:

  1. Fisher RA. 1922. On the interpretation of χ2 from contingency tables, and the calculation of P. Journal of the Royal Statistical Society 8(1), 87–94.