# Measures of association, Concordant and Discordant

I want to calculate concordant and discordant pairs on nx2 tables.

|    Value1   |  Value2  |
|_____________|__________|
|    0.3434   | 1        |
|    0.2132   | 2        |
|    0.3      | 3.3245   |
|    0.6      | 0.12321  |
|    0.745234 | 523      |
|    4        | 0.2134   |
|    3        | 111      |
|    .        | .        |
|    .        | .        |
|    .        | .        |
|    .        | .        |
|    .        | .        |
|_____________|__________|


This is a n x 2 table. How can I calculate concordant and discordant pairs? I am sorry I can't find suitable question tag.

-
Are you sure your question is about Mathematica? – Öskå Jun 23 '14 at 16:08
I have a document about this problem, you can see [link]uregina.ca/~gingrich/gamma.pdf But this is not suitable for me... I can't understand. I found a lot of document about this topic, some of them calculate different the others. – user3646666 Jun 24 '14 at 5:43

SeedRandom[123];
data = 5 + RandomVariate[BinormalDistribution[.5], 20];



Concordant and discordant pairs:

From the documentation on KendallTau

Generalizing @eldo's post we can get the concordant and discordant pairs of observations as follows:

cdpairsF = With[{pairs = Tuples[#, 2]},
Pick[pairs, Sign /@ (Times @@ Subtract @@ # & /@ pairs), #] & /@ {1, -1}] &;
{concordantpairs, discordantpairs} = cdpairsF[data];


Example:

MatrixPlot[
Partition[Sign[Times @@ Subtract @@ #] & /@ Tuples[data, 2], Length[data]],
ColorRules -> {-1 -> Red, 1 -> Green, 0 -> Blue},
Mesh -> True, MeshStyle -> Directive[White, Thick],
PlotLegends -> SwatchLegend[{Red, Green}, {"concordant", "discordant"}]]


Example: Observations concordant/discordant with a reference observation:

SeedRandom[123];
data = 5 + RandomVariate[BinormalDistribution[.5], 100];
{concordantpairs, discordantpairs} = cdpairsF[data];
options = {PlotStyle -> {Blue, Green, Red}, BaseStyle -> PointSize[Large],
Frame -> True,
FrameLabel -> {Style["value1", 14], Style["value2", 14], None, None},
PlotRange -> {{0, 8}, {0, 8}}, AspectRatio -> 1, ImageSize -> 400,

Manipulate[With[{cp = Select[concordantpairs, #[[1]] == data[[k]] &],
dp = Select[discordantpairs, #[[1]] == data[[k]] &]},
ListPlot[{data,
If[# == {}, ## &[], #[[All, 2]]] &@cp,
If[# == {}, ## &[], #[[All, 2]]] &@dp},
GridLines -> List /@ data[[k]], options,
PlotLegends ->
PointLegend[{Blue, Green, Red},
{Style[StringForm["data[[]] = ", k, Round[data[[k]], 0.01]],
Blue, 16],
Style[StringForm[" points \n concordant with data[[]]",Length[cp], k],
Green, 16],
Style[StringForm[" points \n discordant with data[[]]",Length[dp], k],
Red, 16]},
LegendMarkers -> Graphics[Disk[]]]]],
{{k, 1}, 1, Length[data], 1}, ContentSize -> {750, 450}, Alignment -> Center]


Measures of Association:

With Version 9.0.1.0 we have the following measures of association:

KendallTau

SpearmanRho

BlomqvistBeta

GoodmanKruskalGamma

HoeffdingD

{#, # @@ Transpose@data} & /@
{KendallTau, SpearmanRho, BlomqvistBeta, GoodmanKruskalGamma, HoeffdingD}
//  TableForm // Style[#, 20] &


-
I searched so much. But if the table 2xn I didn't find anything :( – user3646666 Jun 23 '14 at 16:57
@user3646666, hope the post and the links are useful. Welcome to mma.se. – kglr Jun 23 '14 at 17:00
I don't think so. Thanks. – user3646666 Jun 23 '14 at 17:03
@user3646666, please note that the data you posted is nx2 (n rows 2 columns); so is the data in my example. – kglr Jun 23 '14 at 17:13
ohh you are right , sorry. It has to be n rows and 2 columns.. nx2 table. I will edit the problem. – user3646666 Jun 24 '14 at 5:40
m = {{{1, 1}, {2, 4}}, {{1, 5}, {2, 4}}, {{1, 1}, {1, 1}}};

Times @@@ (Sign /@ Subtract @@@ m) /. (0 | 1) -> "Concordant" /. -1 -> "Discordant"


{"Concordant", "Discordant", "Concordant"}

-
I couldn't understand anything :( sorry. Can you explain this with mathematics ? – user3646666 Jun 23 '14 at 16:58