Skip to content

Instantly share code, notes, and snippets.

@rtkilian
Created May 12, 2022 21:44
Show Gist options
  • Save rtkilian/356f8f493e76ff628ce24815cc206fb0 to your computer and use it in GitHub Desktop.
Save rtkilian/356f8f493e76ff628ce24815cc206fb0 to your computer and use it in GitHub Desktop.
from scipy.stats import fisher_exact
# Example contingency table
table = [[100, 80],[150, 20]]
# Calculate test statistic and p-value
stat, p = fisher_exact(table)
# Interpreation
print('stat=%.3f, p=%.3f' % (stat, p))
if p > 0.05:
print('Do not reject the null hypothesis and conclude the variables are independent.')
else:
print('Reject the null hypothesis and conclude that the variables are dependent.')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment