rdesctools

function for counting discordant pairs is not working


I am trying to count the number of discordant pairs. For example:

arg1=c("b","c","a","d")
arg2 = c("b","c","d","a")

There is 1 discordant pair in the above (the pair: "a" and "d")

But when I run:

require(asbio)
sum(ConDis.matrix(arg1,arg2)==-1,na.rm=TRUE)

The answer I receive is: 5 (instead of the correct answer - 1)

I also tried:

require(RankAggreg)
require(DescTools)
xy <- table(arg1,arg2)
cd <- ConDisPairs(xy)
cd$D

the answer is 5 again.

What am I missing?


Solution

  • I think you are misunderstanding how ConDis.matrix works.

    The pairs it refers to are pairs of indices of elements and the function checks, for each pair, whether they are moving in the same way in both vectors.

    So, in your vector, you have indeed 5 discordant pairs, that is (considering letters with an ordered quantitative view):

    1. between obs1 and obs3 ("a" is lower than "b" in arg1 but "d" is higher in arg2)
    2. between obs1 and obs4 ("a" is lower than "b" in arg2 but "d" is higher in arg1)
    3. between obs2 and obs3 ("a" is lower than "c" in arg1 but "d" is higher in arg2)
    4. between obs2 and obs4 ("a" is lower than "c" in arg2 but "d" is higher in arg1)
    5. between obs3 and obs4 ("a" is lower than "d" in arg1 but "d" is higher than "a" in arg2)