我已经阅读了其他文章(例如here),以获得分位数的“反向”-即,获得与一系列值中的某个值相对应的百分位数。
但是,对于相同的数据序列,答案并不能为我提供与分位数相同的值。
我还研究了分位数提供9种不同的算法来计算百分位数。
所以我的问题是:是否有可靠的方法来获得分位数函数的反函数?ecdf没有采用“类型”参数,因此似乎无法确保它们使用相同的方法。
可重现的示例:
# Simple data
x = 0:10
pcntile = 0.5
# Get value corresponding to a percentile using quantile
(pcntile_value <- quantile(x, pcntile))
# 50%
# 5 # returns 5 as expected for 50% percentile
# Get percentile corresponding to a value using ecdf function
(pcntile_rev <- ecdf(x)(5))
# [1] 0.5454545 #returns 54.54% as the percentile for the value 5
# Not the same answer as quantile produces
Run Code Online (Sandbox Code Playgroud)