Chi Square test - mauriceling/mauriceling.github.io GitHub Wiki

Purpose: To test whether 2 distributions are equal.

Null hypothesis: Observed distribution = Expected distribution

Alternate hypothesis: Observed distribution ≠ Expected distribution

Note: This test is also known as Pearson's Chi-Square test.

Code:

>>> from scipy import stats
>>> observed = [16, 18, 16, 14, 12, 12]
>>> expected = [16, 16, 16, 16, 16, 8]
>>> result = stats.chisquare(observed, expected)
>>> print("statistic = %.2f" % result[0])
statistic = 3.50
>>> print("p-value = %.2f" % result[1])
p-value = 0.62

Reference:

  1. Pearson K. 1900. On the criterion that a given system of deviations from the probable in the case of a correlated system of variables is such that it can be reasonably supposed to have arisen from random sampling. Philosophical Magazine 5(50), 157-175.