[SciPy-User] stats.pearsonr divide by zero warning

Zachary Pincus zachary.pincus@yale....
Mon Aug 9 14:19:32 CDT 2010


I just svn-up'd scipy, and now find that stats.pearsonr is causing  
divide-by-zero warnings foolishly.

the function contains the following stanzas:

     rs = np.corrcoef(ar,br,rowvar=axisout)

     t = rs * np.sqrt((n-2) / ((rs+1.0)*(1.0-rs)))
     prob = distributions.t.sf(np.abs(t),n-2)*2

     if rs.shape == (2,2):
         return rs[1,0], prob[1,0]
         return rs, prob

Given that the diagonal of the correlation matrix returned by corrcoef  
will *always* be 1s, the t matrix will have divide-by-zero issues on  
the diagonal, and give inf values -- which get zero values for the t- 
distribution's survival function, so everything's fine, output-wise.  
Presumably, though, the t-calculating line should be flanked by err =  
np.seterr(divide='ignore') / np.seterr(**err), right?

Should I add a bug in the tracker? Someone want to just commit this fix?


More information about the SciPy-User mailing list