Kendall rank correlation coefficient (tau-b)
Let $(x_i, y_i), i=1,2,\ldots,N$ be pairs of unique observations of two variables $X, Y$.
For $i < j$,
if $x_i > y_i$ and $x_j > y_j$ or $x_i < y_i$ and $x_j < y_j$,
then the pairs $(x_i, y_i), (x_j, y_j)$ are said concordant.
Otherwise they are discordant.
If $x_i=y_i$ or $x_j=y_j$ they are neither concordant nor discordant.
In this case Kendall's rank coeeficient or correlation is defines as:
$$ \tau_B = \frac{n_c-n_d}{\sqrt{(n_0-n_1)(n_0-n_2)}} $$
$$ \begin{array}{l l} n_0 &= \cfrac{N \times (N-1)} {2} \\ n_c &= \text{number of concordant pairs} \\ n_c &= \text{number of discordant pairs} \\ n_1 &= \text{number of pairs where } x_i = x_j \\ n_2 &= \text{number of pairs where } y_i = y_j \\ \end{array} $$
#include <stdio.h>
#include <iostream>
#include <math.h>
using namespace std;
#define N 4
int main()
{
int i, j;
int nC = 0, nD = 0;
int n0 = N*(N-1) / 2;
int n1 = 0, n2 = 0;
double tau;
double x[N] = {10, 25, 25, 35};
double y[N] = {5, 0, 10, 15};
/*
while (1)
{
cin >> x[i];
cin >> y[i];
++i;
}
printf("i=%d\n", i);
*/
for (i=0; i < (N-1); i++)
{
for (j=i+1; j < N; j++)
{
if ( (x[i] > x[j] && y[i] > y[j]) ||
(x[i] < x[j] && y[i] < y[j]) )
++nC;
if ( (x[i] > x[j] && y[i] < y[j]) ||
(x[i] < x[j] && y[i] > y[j]) )
++nD;
if (x[i] == x[j]) ++n1;
if (y[i] == y[j]) ++n2;
}
}
tau = (double) (nC-nD) / sqrt( (n0-n1) * (n0-n2) );
printf("\nK=%d C=%d D=%d tau=%f\n", n0, nC, nD, tau);
return 0;
}
σχολιασμοί, εξωτερικοί σύνδεσμοι, βοήθεια, ψηφοφορίες, αρχεία, κτλ.
Εκπαιδευτικό υλικό από τον
Αθανάσιο Σταυρακούδη
σας παρέχετε κάτω από την άδεια
Creative Commons Attribution-NonCommercial-ShareAlike 4.0 License.
Σας παρακαλώ να ενημερωθείτε για κάποιους επιπλέον περιορισμούς
http://stavrakoudis.econ.uoi.gr/stavrakoudis/?iid=401.