R使用Stata定义计算百分位数

R calculate percentile using Stata definition

我做了两种不同的分析。一个使用 R,另一个使用 Stata,基于百分位数计算。但是,由于 R 和 Stata 之间的百分位法计算不同,我发现这两个结果不匹配。你知道我是否可以在 R 中使用 Stata 的百分位数定义吗?

R 至少有 9 个分位数和百分位数的定义 只是 quantile(.) * 100This link 表明相应的分位数-type 将是 type=4。我无法在 Base Stata 手册中找到记录的百分位数或分位数函数,但如果有误,欢迎指正。

尼克考克斯是对的。概率为 0.25 的分位数(数据域中的值)是第 25 个百分位数。这个问题在 R-Stata 分歧的两边似乎都不清楚,因为 R 中最初的努力是以未指定的方式使用 ecdf 函数完成的。幸运的是,发帖者被指向 R 分位数函数感到满意。

查看 Version 13 Stata Manual section on centile 后,我不确定它是否与任何 R 分位数方法匹配,尽管它似乎与远离 [=25= 的百分位数的 type=4 方法匹配]:

By default, centile estimates Cq for the variables in varlist and for the values of q given in centile(numlist). It makes no assumptions about the distribution of X, and, if necessary, uses linear interpolation between neighboring sample values. Extreme centiles (for example, the 99th centile in samples smaller than 100) are fixed at the minimum or maximum sample value