KDB:加权中位数
How can one compute weighted median in KDB?
I can see that there is a function med for a simple median but I could not find something like wmed
similar to wavg.
Thank you very much for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以通过复制(使用
where
)来有效地对中位数进行加权:如果您的权重是百分比(例如 0.15 0.10 0.20 0.30 0.25),则将它们转换为等效的整数/计数数字
You could effectively weight the median by duplicating (using
where
):If your weights are percentages (e.g. 0.15 0.10 0.20 0.30 0.25) then convert them to equivalent whole/counting numbers
对于值
v
和权重w
,med v 其中 w
会为较大的w
值吞噬空间。相反,将
w
按v
的升序排序,并查找累计总和达到其总和一半的位置。一些值得注意的矢量技术:
(sum;sums)@\:
并使用 申请.
以及结果上的运算符,而不是设置变量,例如(0.5*sum yi)>sums yi:y i
或定义内部 lambda{ sums[x]<0.5*sum x}y i
iasc
通过并置对另一个多个映射For values
v
and weightsw
,med v where w
gobbles space for larger values ofw
.Instead, sort
w
into ascending order ofv
and look for where cumulative sums reach half their sum.Some vector techniques worth noticing:
(sum;sums)@\:
and using Apply.
and an operator on the result, rather than setting a variable, e.g.(0.5*sum yi)>sums yi:y i
or defining an inner lambda{sums[x]<0.5*sum x}y i
iasc
to sort anotherv i sum ..