Group Abstract Group Abstract

Message Boards Message Boards

0
|
3.3K Views
|
5 Replies
|
4 Total Likes
View groups...
Share
Share this post:

Kendall Tau Distance/Measure of Discordance?

Posted 2 years ago

Might be a trivial question, but while KendallTau is a built-in function, I couldn't find https://en.wikipedia.org/wiki/Kendall_tau_distance (i.e. normalised Discordance) in the function library. Am I wrong? Could anybody help pls? Kind thanks!

POSTED BY: Poomjai Nacaskul
5 Replies

Great thanks. Been quite impressed w/ ChatGPT myself. Cheers!

POSTED BY: Poomjai Nacaskul

Kind thanks

POSTED BY: Poomjai Nacaskul
Posted 2 years ago

yes Mathematica only computes the Kendal correlation Kc. However its relationship with the normalized distance Kn is extremely simple:

Kn:=(1-Kc)/2

as described in the same Wikipedia article

POSTED BY: Updating Name

Kind thanks indeed. I was kinda counting on Wolfram having this as a built-in function, which apparently isn't the case. So your reply is very useful and much appreciated. Sincerely, Poomjai

POSTED BY: Poomjai Nacaskul

Using: ChatGPT to write the code and using example from wikipedia:

  kendallTau[x_, y_, len_] := 
   Module[{i, j, v = 0}, 
    For[i = 0, i < len, i++, 
     For[j = i + 1, j < len, j++, 
      If[x[[i]] < x[[j]] && y[[i]] > y[[j]] || 
        x[[i]] > x[[j]] && y[[i]] < y[[j]], v++]]];
    Abs[v]]; 
  normalize[kt_, len_] := kt/(len*(len - 1)/2)

  list1 = {1, 2, 3, 4, 5};
  list2 = {3, 4, 1, 2, 5};

  normalize[kendallTau[list1, list2, Length[list1]], Length[list1]] // N(*list1 is equal to list2, length are the same*)

  (*0.4*)

or:

 normalize[kendallTau[list1, list2, Length[list2]], Length[list2]] // N

 (*0.4*)
POSTED BY: Mariusz Iwaniuk
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard