Percentile rank calculation

monofonik picture monofonik · Jan 1, 2012 · Viewed 12.2k times · Source

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?

Answer

unutbu picture unutbu · Jan 1, 2012

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