Created
March 27, 2018 11:59
-
-
Save Steboss/c53321be266f55571122060b06634ec6 to your computer and use it in GitHub Desktop.
Kendall tau implementation in C
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
double kendalT(double *x, int len_x, double * y, int len_y) | |
{ | |
//the two array MUST be have the same length | |
int n2=0, n1=0, k, j; | |
int is =0; | |
double aa, a2, a1; | |
for(j=1;j<len_x;j++){ | |
for(k=(j+1);k<=len_x;k++){ | |
a1=x[j]-x[k]; | |
a2=y[j]-y[k]; | |
aa = a1*a2; | |
if (aa) { | |
++n1; | |
++n2; | |
aa>0.0 ? ++is: --is; | |
} | |
else { | |
if (a1) ++n1; | |
if (a2) ++n2; | |
} | |
} | |
} | |
double tau; | |
tau = is/(sqrt((double)n1)*sqrt((double)n2) ); | |
//printf("Tau is %.4f\n", tau); | |
return tau; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment