As I understand it, statsmodels.stats.contingency_tables.Table.test_nominal_association() and scipy.stats.chi2_contingency() refer to the same test, however the results are different:

import numpy as np

### Contingency table
tab = np.array([[6,20],[13,5]])

### SciPy
from scipy.stats import chi2_contingency

print("Chi square test\nChi squared = %f\np           = %f\nDOF         = %d"%(chi_val,p_val,dof))

Chi square test
Chi squared = 8.563275
p           = 0.003430
DOF         = 1
### Statsmodels

import statsmodels.api as sm

table = sm.stats.Table(tab)
res =  table.test_nominal_association()
print (res)

df          1
pvalue      0.0012129356662224922
statistic   10.470535312640576

Is there a fundamental difference between the two stats?


1 Answer 1


scipy uses the continuity correction, statsmodels does not. If you pass correction=False to the scipy test, then the results will be identical.

  • $\begingroup$ Thank you, the results are similar with that option, however it is not clear to me when to use that correction, some sources say when the minimum number of observations in one cell is below 5, others when the number of degrees of freedom is 1... $\endgroup$
    – eurohacker
    Commented Jul 28, 2020 at 6:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.