quantile vs ecdf results

三世轮回 提交于 2020-01-03 18:46:49

问题


I am trying to use ecdf, but I am not sure if I am doing it right. My ultimate purpose is to find what quantile corresponds to a specific value. As an example:

sample_set <- c(20, 40, 60, 80, 100) 
# Now I want to get the 0.75 quantile:
quantile(x = sample_set, probs = 0.75)
#result:
75% 
80
# Let's use ecdf
ecdf(x = sample_set) (80)
#result
0.8

Why is there this discrepancy? Am I doing some trivial mistake, or it depends on the way quantile makes its calculations?

Thanks, Max


回答1:


There are two points. First, as you guessed, it depends on the way quantile makes its calculations. Specifically, it depends on the parameter type. What you might want to choose is type = 1, since then it corresponds to the inverse of empirical distribution function (see ?quantile). Second, since ecdf gives a discrete, step function, i.e. the ecdf is not strictly increasing, you cannot get exact equality because of the way quantile is defined (see the second formula).



来源:https://stackoverflow.com/questions/35927956/quantile-vs-ecdf-results

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