I just recently came accross that there is different defition of quantile() in Julia and Matlab.
I was unable to align the two definitions and always get different result.
我最近才发现在Julia和MatLab中分位数()的定义不同。我无法将这两个定义统一起来,总是得到不同的结果。
Does anybody know why is this a case and how to align their definitions?
有人知道为什么会发生这种情况吗?知道如何调整定义吗?
I tried the following:
我尝试了以下方法:
A = [0.5377, 1.8339 , -2.2588 , 0.8622 , 0.3188, -1.3077, -0.4336];
Q = quantile(A,0.3);
which results in Q = -0.7832.
When I write the same in Julia Statistics library:
这导致Q =-0.7832。当我在Julia Statistics库中编写相同的代码时:
A = [0.5377, 1.8339 , -2.2588 , 0.8622 , 0.3188, -1.3077, -0.4336];
Q1 = quantile(A,0.3);
Q2 = quantile(A,0.3,sorted=true);
which results in Q1=-0.60842 and Q2 = -1.44026. I also tried playing with alpha and beta parameters but it is super tedious and I have no way of knowing if my chosen paramerters hold on the whole range.
结果是Q1=-0.60842,Q2=-1.44026。我也尝试过使用Alpha和Beta参数,但它非常单调乏味,而且我无法知道我选择的参数是否适用于整个范围。
更多回答
Well, when you say sorted=true
but pass an unsorted array, you can’t expect a correct result, so you need to ignore that one. The other difference is just the different interpretation of the concepts. There are many choices to be made. For example, the MATLAB docs extensively describe what the computation is: mathworks.com/help/matlab/ref/quantile.html#btf91zm
嗯,当您说sorted=true但传递一个未排序的数组时,您不能期望得到正确的结果,所以您需要忽略它。另一个不同之处在于对概念的不同解释。有很多选择可供选择。例如,matlab文档广泛地描述了什么是计算:mathworks.com/help/matlab/ref/quantile.html#btf91zm
Maybe setting the alpha
and beta
parameters in Julia you can replicate what MATLAB does? docs.julialang.org/en/v1/stdlib/Statistics/#Statistics.quantile Otherwise you’d have to implement it yourself.
也许在Julia中设置Alpha和Beta参数可以复制matlab所做的事情?Docs.julialang.org/en/v1/stdlib/Statistics/#Statistics.quantile,否则您将不得不自己实现它。
Set alpha=beta=0.5
as Matlab uses type 5 quantile definition.
设置Alpha=Beta=0.5,因为MatLab使用类型5分位数定义。
Note though other software (like R or Python) use the same defaults as Julia (alpha=1
and beta=1
).
请注意,尽管其他软件(如R或Python)使用与Julia相同的默认设置(Alpha=1和Beta=1)。
更多回答
Thank you for your answer. Yes, you are right, by combining what @cris-luengo said about sorted and running your answer as: quantile(A,0.3,alpha=0.5,beta=0.5)
, it gives the same result as Matlab. Thank you.
谢谢你的回答。是的,您是对的,将@cris-Luengo所说的关于排序的内容结合在一起,并将您的答案运行为:分位数(A,0.3,Alpha=0.5,beta=0.5),它得到的结果与MatLab相同。谢谢。
Nonetheless, I find it misleading that sorted=true
for the Julia quantile function says that the input array is sorted rather than sorting the array.
尽管如此,我认为sorted=true这一说法具有误导性,因为Julia decumle函数表示对输入数组进行排序,而不是对数组进行排序。
sorted=true
does say that itr can be assumed to be sorted. That is: set it this way if it is you that guarantees that the data is sorted.
SORTED=TRUE表示可以假定ITR是排序的。也就是说:如果是您保证对数据进行排序,则将其设置为此方式。
我是一名优秀的程序员,十分优秀!