Percentile rank calculation

12,538

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
Share:
12,538
monofonik
Author by

monofonik

MERGE KEEP

Updated on September 15, 2022

Comments

  • monofonik
    monofonik over 1 year

    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
    monofonik over 12 years
    I mustn't have checked my imports properly when testing scipy, thanks for clearing that up. Problem appears to be with statlib only.
  • Josef
    Josef over 12 years
    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 projects.scipy.org/scipy/ticket/560