The function takes a two way table. Assuming your example involves two ordinal 
vectors c(1,2,3,4,5) and c(3,4,1,2,5), you need:

> xy <- table(c(1,2,3,4,5),c(3,4,1,2,5))
> xy
   
    1 2 3 4 5
  1 0 0 1 0 0
  2 0 0 0 1 0
  3 1 0 0 0 0
  4 0 1 0 0 0
  5 0 0 0 0 1
> cd <- ConDisPairs(xy)
> cd
$pi.c
     [,1] [,2] [,3] [,4] [,5]
[1,]    3    2    2    1    0
[2,]    2    1    1    2    1
[3,]    2    1    1    2    2
[4,]    1    2    2    3    3
[5,]    0    1    2    3    4

$pi.d
     [,1] [,2] [,3] [,4] [,5]
[1,]    0    1    2    2    3
[2,]    1    2    2    2    2
[3,]    2    2    2    1    1
[4,]    2    2    1    0    0
[5,]    3    2    1    0    0

$C
[1] 6

$D
[1] 4

Where C is the number of concordant pairs and D is the number of discordant 
pairs. Kendall's tau distance is the number of discordant pairs = 4 and the 
normalized tau is 4/(5*(5-1)/2) = .4.

$pi.c and $pi.d are used to compute C and D as follows:

> sum((xy * cd$pi.c))/2
[1] 6
> sum((xy * cd$pi.d))/2
[1] 4


David L. Carlson
Department of Anthropology
Texas A&M University


-----Original Message-----
From: Ragia Ibrahim [mailto:ragi...@hotmail.com] 
Sent: Saturday, September 12, 2015 4:21 AM
To: David L Carlson <dcarl...@tamu.edu>; r-help@r-project.org
Subject: RE: [R] kendall tau distance

many thanks for replying.
 I have the vectors
 running the code

ConDisPairs( data.frame(c(1,2,3,4,5),c(3,4,1,2,5)) ) 

$pi.c
     [,1] [,2]
[1,]   12    0
[2,]    8    1
[3,]    7    3
[4,]    5    6
[5,]    0   10

$pi.d
     [,1] [,2]
[1,]    0   14
[2,]    3   12
[3,]    7    9
[4,]    8    5
[5,]   10    0

$C
[1] 69

$D
[1] 109


I could not find the result related to the result at wiki page in any 
way..looking for 4 ? dissimilar pairs?

many thanks

----------------------------------------
> From: dcarl...@tamu.edu
> To: ragi...@hotmail.com; r-help@r-project.org
> Subject: RE: [R] kendall tau distance
> Date: Fri, 11 Sep 2015 15:37:19 +0000
>
> The Wikipedia article gives a simple formula based on the number of 
> discordant pairs. You can get that from the ConDisPairs() function in package 
> DescTools.
>
> -------------------------------------
> David L Carlson
> Department of Anthropology
> Texas A&M University
> College Station, TX 77840-4352
>
> -----Original Message-----
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Ragia Ibrahim
> Sent: Thursday, September 10, 2015 12:40 PM
> To: r-help@r-project.org
> Subject: [R] kendall tau distance
>
> Dear group
> how to calculate kendall tau distance according to Kendall_tau_distance at 
> wikipedia
>
> <a 
> href="https&#58;&#47;&#47;en.wikipedia.org&#47;wiki&#47;Kendall_tau_distance" 
> target="_blank" 
> class="newlyinsertedlink">https&#58;&#47;&#47;en.wikipedia.org&#47;wiki&#47;Kendall_tau_distance</a>
>
>
> thanks in advance
> Ragia
> ______________________________________________
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
                                          

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to