Skip to content

percentile method

ETCCDI is rather specific when it comes to percentiles, cf. [1]. Mention #75 (closed), #148 (closed), #175 (closed)

The specified method, Hyndman & Fan no. 8, is available in scipy.stats.mstats.mquantiles. It would be useful to make use of it if not too detrimental to timing. So I did a very quick test (patterned after some Stack Exchange answer):


setup = '''
import random
import numpy as np
import scipy.stats.mstats as mstats

random.seed('slartibartfast')
s = [random.random() for i in range(1000)]
p = 35
third = 1./3. # this particular value gives H&F#8
numper = lambda x: np.percentile(x, p)
statper = lambda x: mstats.mquantiles(x, [p/100.], alphap=third, betap=third)
'''

print(min(timeit.Timer('x=s[:]; statper(x)', setup=setup).repeat(7, 1000)))
# 2.9134851020062342

print(min(timeit.Timer('x=s[:]; numper(x)', setup=setup).repeat(7, 1000)))
# 0.1574339639628306

This does not look overly promising, so I suggest that we leave this for now. Let's see what they might come up with over at numpy, cf. [1]

[1] Wiki page

Edited by Lars Bärring