Kendall rank correlation coefficient (tau-a)
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_A = \frac{n_c-n_d}{n_0} $$
$$ \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} \\ \end{array} $$
#include <stdio.h>
using namespace std;
#define N 4
int main()
{
int i, j;
double x[N] = {10, 25, 30, 35};
double y[N] = {5, 10, 7, 15};
int C = 0, D = 0;
int K = 0;
double tau;
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]) ) C++;
if ( (x[i] > x[j] && y[i] < y[j]) ||
(x[i] < x[j] && y[i] > y[j]) ) D++;
K++;
printf("K=%d : i=%d j=%d C=%d D=%d\n", K, i, j, C, D);
}
}
tau = (double) (C-D) / (N*(N-1) / 2);
printf("\nK=%d C=%d D=%d tau=%f\n", K, C, D, tau);
return 0;
}
σχολιασμοί, εξωτερικοί σύνδεσμοι, βοήθεια, ψηφοφορίες, αρχεία, κτλ.
Εκπαιδευτικό υλικό από τον
Αθανάσιο Σταυρακούδη
σας παρέχετε κάτω από την άδεια
Creative Commons Attribution-NonCommercial-ShareAlike 4.0 License.
Σας παρακαλώ να ενημερωθείτε για κάποιους επιπλέον περιορισμούς
http://stavrakoudis.econ.uoi.gr/stavrakoudis/?iid=401.