def mackinnonp(teststat, regression='c', N=1, lags=None):
 maxstat = eval(('tau_max_' + regression))
 minstat = eval(('tau_min_' + regression))
 starstat = eval(('tau_star_' + regression))
 if (teststat > maxstat[(N - 1)]):
  return 1.0
 elif (teststat < minstat[(N - 1)]):
  return 0.0
 if (teststat <= starstat[(N - 1)]):
  tau_coef = eval((((('tau_' + regression) + '_smallp[') + str((N - 1))) + ']'))
 else:
  tau_coef = eval((((('tau_' + regression) + '_largep[') + str((N - 1))) + ']'))
 return norm.cdf(polyval(tau_coef[::(-1)], teststat))

def mackinnonp ( teststat , regression = 'c' , N = 1 , lags = None ) : maxstat = eval ( ( 'tau_max_' + regression ) ) minstat = eval ( ( 'tau_min_' + regression ) ) starstat = eval ( ( 'tau_star_' + regression ) ) if ( teststat > maxstat [ ( N - 1 ) ] ) : return 1.0 elif ( teststat < minstat [ ( N - 1 ) ] ) : return 0.0 if ( teststat <= starstat [ ( N - 1 ) ] ) : tau_coef = eval ( ( ( ( ( 'tau_' + regression ) + '_smallp[' ) + str ( ( N - 1 ) ) ) + ']' ) ) else : tau_coef = eval ( ( ( ( ( 'tau_' + regression ) + '_largep[' ) + str ( ( N - 1 ) ) ) + ']' ) ) return norm . cdf ( polyval ( tau_coef [ : : ( - 1 ) ] , teststat ) )
returns mackinnons approximate p-value for teststat .