Skip to content

Instantly share code, notes, and snippets.

@rtkilian
Created May 12, 2022 21:42
Show Gist options
  • Save rtkilian/34b4786938fba39f35c561d2063409df to your computer and use it in GitHub Desktop.
Save rtkilian/34b4786938fba39f35c561d2063409df to your computer and use it in GitHub Desktop.
from scipy.stats import chi2_contingency
# Example contingency table
table = [[100, 80, 70],[150, 20, 80]]
# Calculate test statistic and p-value
stat, p, dof, expected = chi2_contingency(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