[Scipy-tickets] [SciPy] #822: stats.spearmanr has incorrect tie handling

SciPy scipy-tickets@scipy....
Sun Dec 21 23:31:58 CST 2008


#822: stats.spearmanr has incorrect tie handling
-------------------------+--------------------------------------------------
 Reporter:  josefpktd    |       Owner:  josefpktd
     Type:  defect       |      Status:  new      
 Priority:  normal       |   Milestone:           
Component:  scipy.stats  |     Version:           
 Severity:  normal       |    Keywords:           
-------------------------+--------------------------------------------------
 {{{
 >>> a1=array([1, 2, 1, 2, 0, 0, 1, 1, 1, 1])
 >>> a1=np.array([1, 2, 1, 2, 0, 0, 1, 1, 1, 1])
 >>> a2=np.array([0, 0, 2, 2, 0, 0, 0, 0, 0, 2])

 mstats has tie handling

 >>> stats.mstats.spearmanr(a1,a2)
 (0.34503277967117713, masked_array(data = 0.328856977066,
       mask = False,
       fill_value=1e+020)
 )

 stats uses short cut formula that is incorrect with ties

 >>> stats.spearmanr(a1,a2)
 (0.53636363636363638, 0.10997259642580841)

 correct calculation can be done with np.corrcoef, no complicated tie
 handling and calculation necessary

 >>> a1r=stats.rankdata(a1)
 >>> a2r=stats.rankdata(a2)
 >>> np.corrcoef(a1r,a2r)[0,1]
 0.34503277967117718
 }}}

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


More information about the Scipy-tickets mailing list