10

I'm attempting to calculate the percentile rank of a score using the python statlib module. The percentileofscore function is supposed to return a value between 0 and 100, however it regularly produces numbers outside this range. An example:

 >> a = [0,1,2,3,4,5]
 >> percentileofscore(a, 0)
 108.33333333333333

I've tried the scipy module, and have also rolled my own with similar results.

Am I misunderstanding something re. this function?

EDIT - More examples:

 percentileofscore([23,23,23,25], 23)
 137.5
 percentileofscore([12,19,65,25], 12)
 112.5
 percentileofscore([112,109,605,25], 25)
 112.5

Seems that querying the percentile of the lowest score causes the problem. A bug perhaps?

monofonik
  • 2,735
  • 3
  • 20
  • 17

1 Answers1

8

scipy.stats.percentileofscore seems to work as expected:

In [2]: import scipy.stats as stats

In [3]: stats.percentileofscore([0,1,2,3,4,5], 0)
Out[3]: 16.666666666666664
unutbu
  • 842,883
  • 184
  • 1,785
  • 1,677
  • I mustn't have checked my imports properly when testing scipy, thanks for clearing that up. Problem appears to be with statlib only. – monofonik Jan 01 '12 at 03:21
  • I don't think statlib is maintained, while there have been several bugfixes and improvements in scipy.stats in the code that was initially inherited from statlib, for example for this case http://projects.scipy.org/scipy/ticket/560 – Josef Jan 02 '12 at 05:11