def normal_power(effect_size, nobs, alpha, alternative='two-sided', sigma=1.0):
 d = effect_size
 if (alternative in ['two-sided', '2s']):
  alpha_ = (alpha / 2.0)
 elif (alternative in ['smaller', 'larger']):
  alpha_ = alpha
 else:
  raise ValueError(("alternative has to be 'two-sided', 'larger' " + "or 'smaller'"))
 pow_ = 0
 if (alternative in ['two-sided', '2s', 'larger']):
  crit = stats.norm.isf(alpha_)
  pow_ = stats.norm.sf((crit - ((d * np.sqrt(nobs)) / sigma)))
 if (alternative in ['two-sided', '2s', 'smaller']):
  crit = stats.norm.ppf(alpha_)
  pow_ += stats.norm.cdf((crit - ((d * np.sqrt(nobs)) / sigma)))
 return pow_

def normal_power ( effect_size , nobs , alpha , alternative = 'two-sided' , sigma = 1.0 ) : d = effect_size if ( alternative in [ 'two-sided' , '2s' ] ) : alpha_ = ( alpha / 2.0 ) elif ( alternative in [ 'smaller' , 'larger' ] ) : alpha_ = alpha else : raise ValueError ( ( "alternative has to be 'two-sided', 'larger' " + "or 'smaller'" ) ) pow_ = 0 if ( alternative in [ 'two-sided' , '2s' , 'larger' ] ) : crit = stats . norm . isf ( alpha_ ) pow_ = stats . norm . sf ( ( crit - ( ( d * np . sqrt ( nobs ) ) / sigma ) ) ) if ( alternative in [ 'two-sided' , '2s' , 'smaller' ] ) : crit = stats . norm . ppf ( alpha_ ) pow_ += stats . norm . cdf ( ( crit - ( ( d * np . sqrt ( nobs ) ) / sigma ) ) ) return pow_
calculate power of a normal distributed test statistic .