def pearsonr(x, y):
 (x, y, n) = _chk_size(x, y)
 (x, y) = (x.ravel(), y.ravel())
 m = ma.mask_or(ma.getmask(x), ma.getmask(y))
 n -= m.sum()
 df = (n - 2)
 if (df < 0):
  return (masked, masked)
 (mx, my) = (x.mean(), y.mean())
 (xm, ym) = ((x - mx), (y - my))
 r_num = ma.add.reduce((xm * ym))
 r_den = ma.sqrt((ma.dot(xm, xm) * ma.dot(ym, ym)))
 r = (r_num / r_den)
 r = min(r, 1.0)
 r = max(r, (-1.0))
 df = (n - 2)
 if ((r is masked) or (abs(r) == 1.0)):
  prob = 0.0
 else:
  t_squared = (((df / ((1.0 - r) * (1.0 + r))) * r) * r)
  prob = _betai((0.5 * df), 0.5, (df / (df + t_squared)))
 return (r, prob)

def pearsonr ( x , y ) : ( x , y , n ) = _chk_size ( x , y ) ( x , y ) = ( x . ravel ( ) , y . ravel ( ) ) m = ma . mask_or ( ma . getmask ( x ) , ma . getmask ( y ) ) n -= m . sum ( ) df = ( n - 2 ) if ( df < 0 ) : return ( masked , masked ) ( mx , my ) = ( x . mean ( ) , y . mean ( ) ) ( xm , ym ) = ( ( x - mx ) , ( y - my ) ) r_num = ma . add . reduce ( ( xm * ym ) ) r_den = ma . sqrt ( ( ma . dot ( xm , xm ) * ma . dot ( ym , ym ) ) ) r = ( r_num / r_den ) r = min ( r , 1.0 ) r = max ( r , ( - 1.0 ) ) df = ( n - 2 ) if ( ( r is masked ) or ( abs ( r ) == 1.0 ) ) : prob = 0.0 else : t_squared = ( ( ( df / ( ( 1.0 - r ) * ( 1.0 + r ) ) ) * r ) * r ) prob = _betai ( ( 0.5 * df ) , 0.5 , ( df / ( df + t_squared ) ) ) return ( r , prob )
calculates a pearson correlation coefficient and the p-value for testing non-correlation .