In [1]:
import warnings
warnings.filterwarnings('ignore')

In [3]:
%matplotlib inline
%pylab inline


Populating the interactive namespace from numpy and matplotlib

In [4]:
# https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.chisquare.html

In [14]:
from scipy.stats import chisquare

In [15]:
observations = [16, 18, 16, 14, 12, 12]

In [16]:
chisquare(observations)


Out[16]:
Power_divergenceResult(statistic=2.0, pvalue=0.84914503608460956)

In [ ]:
= [16, 16, 16, 16, 16, 8]

In [7]:
chisquare(observations, f_exp=)


Out[7]:
Power_divergenceResult(statistic=3.5, pvalue=0.62338762774958223)

In [8]:
obs = np.array([[16, 18, 16, 14, 12, 12], [32, 24, 16, 28, 20, 24]]).T

In [9]:
obs


Out[9]:
array([[16, 32],
       [18, 24],
       [16, 16],
       [14, 28],
       [12, 20],
       [12, 24]])

In [10]:
chisquare(obs)


Out[10]:
Power_divergenceResult(statistic=array([ 2.        ,  6.66666667]), pvalue=array([ 0.84914504,  0.24663415]))

In [11]:
chisquare(obs, axis=None)


Out[11]:
Power_divergenceResult(statistic=23.31034482758621, pvalue=0.015975692534127565)

In [12]:
obs.ravel()


Out[12]:
array([16, 32, 18, 24, 16, 16, 14, 28, 12, 20, 12, 24])

In [13]:
chisquare([16, 18, 16, 14, 12, 12], ddof=1)
(2.0, 0.73575888234288467)


Out[13]:
(2.0, 0.7357588823428847)

In [18]:
# http://vassarstats.net/textbook/ch8pt1.html

chisquare([89, 120, 91])


Out[18]:
Power_divergenceResult(statistic=6.0199999999999996, pvalue=0.049291678760462164)

In [19]:
chisquare([89, 120, 91], [100, 100, 100])


Out[19]:
Power_divergenceResult(statistic=6.0199999999999996, pvalue=0.049291678760462164)

In [ ]: