[Scipy-tickets] [SciPy] #1259: stats.spearmanr causes unnecessary divide-by-zero warnings

SciPy Trac scipy-tickets@scipy....
Mon Aug 9 16:47:50 CDT 2010

#1259: stats.spearmanr causes unnecessary divide-by-zero warnings
 Reporter:  zachrahan  |       Owner:  somebody
     Type:  defect     |      Status:  new     
 Priority:  normal     |   Milestone:  0.9.0   
Component:  Other      |     Version:  devel   
 Keywords:             |  
 scipy.stats.spearmanr 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.

 Should the t-calculating line should be flanked by err =
 np.seterr(divide='ignore') / np.seterr(**err)? Or by adding TINY to the

Ticket URL: <http://projects.scipy.org/scipy/ticket/1259>
SciPy <http://www.scipy.org>
SciPy is open-source software for mathematics, science, and engineering.

More information about the Scipy-tickets mailing list