[Scipy-tickets] [SciPy] #1823: kendalltau does not return -1 for reversed list.

SciPy Trac scipy-tickets@scipy....
Fri Jan 25 15:23:44 CST 2013


#1823: kendalltau does not return -1 for reversed list.
-------------------------+--------------------------------------------------
 Reporter:  jdean        |       Owner:  rgommers   
     Type:  defect       |      Status:  new        
 Priority:  normal       |   Milestone:  Unscheduled
Component:  scipy.stats  |     Version:  0.11.0     
 Keywords:               |  
-------------------------+--------------------------------------------------
Changes (by josefpktd):

  * owner:  somebody => rgommers
  * component:  Other => scipy.stats


Old description:

> I'm getting an unexpected result from stats.kendalltau.  I expect to
> get a correlation of -1 for reversed lists, and sometimes I don't.
>
> Setup:
> - I copied the kendalltau algorithm out of scipy.stats.stats.py, and
>   created scipy_kendalltau.
>   - This was a fresh source distribution 2013/01/25.
>
> - Add to the beginning of this new file:
> import numpy as np
> from math import erfc   # NOTE: This may be an issue
>
> # Start an ipython session.
> # Import the scipy kendalltau
> In [3]: from scipy_kendalltau import kendalltau
> # Import another version of kendall's tau
> In [4]: from compare_lists import kendalls_tau
>
> In [5]: a = [1,3,5,2,4,6]
> In [6]: arev = [6,4,2,5,3,1]
>
> # Behaves as expected for a reversed list, in both versions.
> In [7]: kendalltau(a, arev)
> Out[7]: (-1.0, 0.004832241997291933)
>
> In [8]: kendalls_tau(a, arev)
> Out[8]: -1.0
>
> # Now try a longer list.
> In [9]: x = [5, 32, 78, 48, 79, 110, 57, 17, 45, 24, 35, 22, 83, 25, 64,
> 80, 53, 3, 20, 23, 33\
> , 54, 65, 26, 109, 4, 7, 105, 55, 8, 1, 21, 46, 82, 95, 15, 2, 52, 104,
> 97, 85, 66, 86, 34, 10\
> 1, 88, 61, 106, 9, 81, 13, 10, 91, 72, 99, 102, 43, 27, 74, 89, 6, 96,
> 107, 70, 38, 36, 56, 10\
> 8, 16, 93, 67, 18, 90, 49, 92, 68, 98, 19, 39, 73, 40, 12, 103, 50, 75,
> 47, 11, 0, 28, 44, 58,\
>  30, 94, 59, 41, 37, 62, 69, 14, 60, 76, 100, 29, 51, 84, 77, 63, 42, 87,
> 31, 71]
>
> In [10]: xrev = x[:]
> In [11]: xrev.reverse()
>
> # The other version works as expected: -1 correlation for a reversed
> list.
> In [12]: kendalls_tau(x, xrev)
> Out[12]: -1.0
>
> # Oops run that again.
> In [13]: kendalls_tau(x, xrev)
> Out[13]: -1.0
>
> # But the scipy version gives an unexpected answer in this case.
> # - expected: -1 as the first return value
> # - got: -0.067649...
> In [14]: kendalltau(x, xrev)
> Out[14]: (-0.067649467649467651, 0.2925775144715035)
>
> Thank you,
> - Jim
>
> PS.  Please contact me via email (james@echonest.com) if
> you have any questions, as I only joined scipy so I could
> report this, and I won't see replies here.

New description:

 I'm getting an unexpected result from stats.kendalltau.  I expect to
 get a correlation of -1 for reversed lists, and sometimes I don't.

 Setup:
 - I copied the kendalltau algorithm out of scipy.stats.stats.py, and
   created scipy_kendalltau.
   - This was a fresh source distribution 2013/01/25.

 - Add to the beginning of this new file:

 {{{
 import numpy as np
 from math import erfc   # NOTE: This may be an issue
 }}}

 {{{
 # Start an ipython session.
 # Import the scipy kendalltau
 In [3]: from scipy_kendalltau import kendalltau
 # Import another version of kendall's tau
 In [4]: from compare_lists import kendalls_tau

 In [5]: a = [1,3,5,2,4,6]
 In [6]: arev = [6,4,2,5,3,1]

 # Behaves as expected for a reversed list, in both versions.
 In [7]: kendalltau(a, arev)
 Out[7]: (-1.0, 0.004832241997291933)

 In [8]: kendalls_tau(a, arev)
 Out[8]: -1.0

 # Now try a longer list.
 In [9]: x = [5, 32, 78, 48, 79, 110, 57, 17, 45, 24, 35, 22, 83, 25, 64,
 80, 53, 3, 20, 23, 33\
 , 54, 65, 26, 109, 4, 7, 105, 55, 8, 1, 21, 46, 82, 95, 15, 2, 52, 104,
 97, 85, 66, 86, 34, 10\
 1, 88, 61, 106, 9, 81, 13, 10, 91, 72, 99, 102, 43, 27, 74, 89, 6, 96,
 107, 70, 38, 36, 56, 10\
 8, 16, 93, 67, 18, 90, 49, 92, 68, 98, 19, 39, 73, 40, 12, 103, 50, 75,
 47, 11, 0, 28, 44, 58,\
  30, 94, 59, 41, 37, 62, 69, 14, 60, 76, 100, 29, 51, 84, 77, 63, 42, 87,
 31, 71]

 In [10]: xrev = x[:]
 In [11]: xrev.reverse()

 # The other version works as expected: -1 correlation for a reversed list.
 In [12]: kendalls_tau(x, xrev)
 Out[12]: -1.0

 # Oops run that again.
 In [13]: kendalls_tau(x, xrev)
 Out[13]: -1.0

 # But the scipy version gives an unexpected answer in this case.
 # - expected: -1 as the first return value
 # - got: -0.067649...
 In [14]: kendalltau(x, xrev)
 Out[14]: (-0.067649467649467651, 0.2925775144715035)
 }}}

 Thank you,
 - Jim

 PS.  Please contact me via email (james@echonest.com) if
 you have any questions, as I only joined scipy so I could
 report this, and I won't see replies here.

--

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


More information about the Scipy-tickets mailing list