如何精确匹配累积分布函数和分位数函数的结果?

How to exactly match the result of cumulative distribution function and quantile function?

我们知道,quantile函数是逆累积分布函数。

那么对于一个已经存在的distribution(a vector),如何精确匹配cumulative distribution functionquantile函数的结果呢?

这里有一个在 MATLAB 中给出的例子。

a = [150   154   151   153   124]
[x_count, x_val] = hist(a, unique(a));
% compute the probability cumulative distribution 
p = cumsum(n)/sum(n);
x_out = quantile(a, p)

在累积分布函数中,累积概率与x值的对应关系应为:

x = 124   150   151   153   154
p = 0.2000    0.4000    0.6000    0.8000    1.0000

但是使用pquantile来计算x_out,结果与 x:

不同
x_out =

  137.0000  150.5000  152.0000  153.5000  154.0000

参考

  1. quantile function
  2. matlab quantile function

来自docs

For a data vector of five elements such as {6, 3, 2, 10, 1}, the sorted elements {1, 2, 3, 6, 10} respectively correspond to the 0.1, 0.3, 0.5, 0.7, 0.9 quantiles.

因此,如果您想得到为 x 输入的确切数字,并且您的 x 有 5 个元素,那么您的 p 需要 p = [0.1, 0.3, 0.5, 0.7, 0.9].完整的算法在文档中明确定义。

您假设要恢复 xp 应该是 [0.2, 0.4, 0.6, 0.8, 1]。但是为什么不p = [0, 0.2, 0.4, 0.6, 0.8]呢? Matlab的算法好像只是对两种方法取线性平均。

注意R defines9种分位数的不同算法,所以你的假设需要说清楚。