我已经阅读了关于获取分位数“反向”的其他帖子(例如此处) - 即获取与一系列值中的某个值相对应的百分位数。
但是,对于相同的数据系列,答案并没有给我与分位数相同的值。
我还研究了分位数提供了 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