How to make a sample from the empirical distribution function

懵懂的女人 提交于 2019-12-23 15:28:52

问题


I'm trying to implement the nonparametric bootstrapping on Python. It requires to take a sample, build an empirical distribution function from it and then to generate a bunch of samples from this edf. How can I do it? In scipy I found only how to make your own distribution function if you know the exact formula describing it, but I have only an edf.


回答1:


The edf you get by sorting the samples:

N = samples.size
ss = np.sort(samples) # these are the x-values of the edf
                      # the y-values are 1/(2N), 3/(2N), 5/(2N) etc.
edf = lambda x: np.searchsorted(ss, x) / N

However, if you only want to resample then you simply draw from your sample with equal probability and replacement.

If this is too "steppy" for your liking, you can probably use some kind of interpolation to get a smooth distribution.



来源:https://stackoverflow.com/questions/42541421/how-to-make-a-sample-from-the-empirical-distribution-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!