On Sat, 2 Jul 2011, yinung at Gmail wrote:
Yes, thanks for your great script, but...
It works only there are no redundant values within x~y
For example,
x = {1,2,3,4}' and
y={1,3,5,7,9}' ,
then w1 should be 15 rather than 14 ...
The problem is actually the ties. (If the series are of different
lengths you just put the shorter one first.) This fixes the ties
issue:
<hansl>
nulldata 9
matrix mx = {1,2,3,4}'
matrix my = {1,3,5,7,9}'
matrix Z = (mx ~ 1) | (my ~ 0)
Z = msortby(Z, 1)
series s = Z[,1]
matrix r = ranking(s)
Z = Z ~ r
Z
w1 = sumc(selifr(Z[,3], Z[,2]))
</hansl>
However, the need to go back and forth between matrices and series
is not very elegant. In CVS I have now enabled the ranking()
function for vectors. So this will now work:
<hansl>
matrix mx = {1,2,3,4}'
matrix my = {1,3,5,7,9}'
matrix Z = msortby((mx ~ 1) | (my ~ 0), 1)
w1 = sumc(selifr(ranking(Z[,1]), Z[,2]))
</hansl>
Allin