我刚开始使用 Julia,我正在尝试做一些简单的统计。
我正在使用 StatsBase 包并尝试计算分位数。
using StatsBase
lst = 1:10
print(nquantile(lst, 4))
得到
[1.0, 3.25, 5.5, 7.75, 10.0]
我假设 Q_1 = 3.25 和 Q_2 = 7.75
在 python 上运行类似的代码:
from statistics import quantiles
lst = [_ for _ in range(1, 11)]
print(quantiles(lst))
产量:
[2.75, 5.5, 8.25]
其中 Q_1 = 2.75 和 Q_3 = 8.25。
根据我对统计学的理解,pythons 结果对应于实际数学是什么。
因此,我猜测 Julia 变体正在使用某种高斯分布来查找分位数。如果是这样,有没有办法让它服从均匀分布?
最佳答案
有许多分位数定义,Julia 实现了 Hyndman, R.J 和 Fan, Y. (1996) Sample Quantiles in Statistical Packages 中的所有选项,美国统计学家,第 50 卷,第 4 期,第361-365
为了获得 Python 的等价物,请执行以下操作:
julia> quantile(1:10, (0:4)/4; alpha=0,beta=0)
5-element Vector{Float64}:
1.0
2.75
5.5
8.25
10.0
解释(在文档中找到):
help?> nquantile
(...)
Equivalent to quantile(x, [0:n]/n).
(...)
help?> quantile
quantile(itr, p; sorted=false, alpha::Real=1.0, beta::Real=alpha)
(...)
By default (alpha = beta = 1), quantiles are computed via linear interpolation between the points ((k-1)/(n-1),
v[k]), for k = 1:n where n = length(itr). This corresponds to Definition 7 of Hyndman and Fan (1996), and is the same as the R and NumPy default.
(...)
• Def. 6: alpha=0, beta=0 (Excel PERCENTILE.EXC, Python default, Stata altdef)
(...)
关于statistics - 在 Julia 与 Python 中使用分位数时出现意外结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73704029/