3

I have some discrete data values, that taken together form some sort of distribution. This is one of them, but they are different with the peak being in all possible locations, from 0 to end. enter image description here

So, I want to use it's quantiles (percentiles) in Python. I think I could write some sort of function, that would some up all values starting from zero, until it reaches desired percent. But probably there is a better solution? For example, to create an empirical distribution of some sort in SciPy and then use SciPy's methods of calculating percentiles?

In the very end I need x-coordinates of a left percentile and a right percentile. One could use 20% and 80% percentiles as an example, I will have to find the best numbers for my case later.

Thank you in advance!

EDIT: some example code for almost what I want.

import numpy as np
np.random.seed(0)
distribution = np.random.normal(0, 1, 1000)
left, right = np.percentile(distribution, [20, 80])
print left, right

This returns percentiles themselves, I need to get their x-coordinates somehow. For normal distribution here it is possible, obviously, but I have a distribution of an unknown shape, so if a percentile isn't equal to one of the values (which is the most common thing, obviously), it becomes much more complicated.

4

2 に答える 2

2

経験的 CDF を探している場合は、 statsmodels ECDFを使用できます。パーセンタイル/分位数の場合、numpyパーセンタイルを使用できます

于 2013-12-24T20:10:55.063 に答える
0

OK、今のところ、次の関数を作成して使用します。

def percentile(distribution, percent):
    percent = 1.0*percent/100
    cum_percent = 0
    i=0
    while cum_percent <= percent:        
        cum_percent = cum_percent + distribution[i]
        i = i+1
    return i

必要な値の左側にある最も近い値のインデックスを返すため、少し大雑把です。私の目的では、一時的な解決策として機能しますが、正確なパーセンタイルの x 座標を決定するための実用的な解決策を見たいと思っています。

于 2013-12-24T21:48:19.997 に答える