Home › Forums › kdb+ › how to understand the below code › Re: how to understand the below code
-
Lets see what we can infer.
.quantQ.stats.kendallTauRank:{[xS;yS] //xS,yS -- arrays of values to compare the rank // aggregate concordance statictics stats: sum raze {.quantQ.stats.concordanceRoutine/:[y;(1+x?y)_x]}[t] each t: flip(xS,yS); // return kendall's tau rank :(stats[0]-stats[1])%0.5*count[xS]*count[xS]-1; }
flip(xS,yS)
tells us thatxS
andyS
must be same-width matrices otherwise there would be nothing to flip.The binary lambda
{.quantQ.stats.concordanceRoutine/:[y;(1+x?y)_x]}
is projected ont
, which thus becomes they
in the lambda.The lambda could equally be written
{y .quantQ.stats.concordanceRoutine/:(1+x?y)_x}
from which it might be clearer how, withx
set tot
, the binary concordance routine is being iterated: each row oft
against the rows that follow it.Two ways to express the same iteration:
raze{.quantQ.stats.concordanceRoutine/:[y;(1+x?y)_x]}[t] each t t .quantQ.stats.concordanceRoutine'(1+til count t)_: t
Line 6 defines the result. Omitting the explicit Return
:
and the trailing semicolon would be better style.stats
would be three integers; the difference could also be written-/[2#stats]
.