Skip to content

Instantly share code, notes, and snippets.

@Steboss
Created March 27, 2018 11:59
Show Gist options
  • Save Steboss/c53321be266f55571122060b06634ec6 to your computer and use it in GitHub Desktop.
Save Steboss/c53321be266f55571122060b06634ec6 to your computer and use it in GitHub Desktop.
Kendall tau implementation in C
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