这里的另一种方法。我想你在问估计概率积分变换。这段代码产生了一个相当细致的估计,即inverted_edf
。
它通过以不同的值计算SAMPLE
中点之间的线性内插来进行。然后它计算样本经验df,最后是inverted_edf
。
我应该提到,即使样本量为1,000,尾巴的百分位数也会有相当大的统计变异性,尽管0.5的样本量会少一些。
import statsmodels.distributions.empirical_distribution as edf
from scipy.interpolate import interp1d
import numpy as np
import matplotlib.pyplot as plt
SAMPLE = np.random.normal(0, 1, 1000)
sample_edf = edf.ECDF(SAMPLE)
slope_changes = sorted(set(SAMPLE))
sample_edf_values_at_slope_changes = [ sample_edf(item) for item in slope_changes]
inverted_edf = interp1d(sample_edf_values_at_slope_changes, slope_changes)
x = np.linspace(0.005, 1)
y = inverted_edf(x)
#~ plt.plot(x, y, 'ro', x, y, 'b-')
plt.plot(x, y, 'b-')
plt.show()
p = 0.5
print ('%s percentile:' % (100*p), inverted_edf(p))
下面是两次运行的图形和文本输出。
50.0 percentile: -0.05917394517540461
50.0 percentile: -0.0034011090849578695