def chi_square_test(observed, expected, alpha=0.05, df=None):
 if (df is None):
  df = (observed.size - 1)
 if (alpha == 0.01):
  alpha_idx = 0
 elif (alpha == 0.05):
  alpha_idx = 1
 else:
  raise ValueError('support only alpha == 0.05 or 0.01')
 chi_square = numpy.sum((((observed - expected) ** 2) / expected))
 return (chi_square < chi_square_table[alpha_idx][df])

def chi_square_test ( observed , expected , alpha = 0.05 , df = None ) : if ( df is None ) : df = ( observed . size - 1 ) if ( alpha == 0.01 ) : alpha_idx = 0 elif ( alpha == 0.05 ) : alpha_idx = 1 else : raise ValueError ( 'support only alpha == 0.05 or 0.01' ) chi_square = numpy . sum ( ( ( ( observed - expected ) ** 2 ) / expected ) ) return ( chi_square < chi_square_table [ alpha_idx ] [ df ] )
testing goodness-of-fit test with pearsons chi-squared test .