def chi2prob(x, df, direction='high'):
 if (x <= 0):
  return nan
 elif (direction == 'high'):
  return (1.0 - chi2.cdf(x, df))
 elif (direction == 'low'):
  return chi2.cdf(x, df)
 else:
  raise ValueError('Unknown direction.')

def chi2prob ( x , df , direction = 'high' ) : if ( x <= 0 ) : return nan elif ( direction == 'high' ) : return ( 1.0 - chi2 . cdf ( x , df ) ) elif ( direction == 'low' ) : return chi2 . cdf ( x , df ) else : raise ValueError ( 'Unknown direction.' )
return the chi-squared statistic .