/* * $Id: spearman-rank-correlation.c $ * * $Log$ * */ #include #include "macros.h" #include "spearman-rank-correlation.h" static int compare_spearman_rank_t_data(const void *a, const void *b); static int compare_spearman_rank_t_orig_rank(const void *a, const void *b); /* * spearman_rank_correlation: * Returns the product moment correlation coefficient of the ranked input. */ double spearman_rank_correlation( int n, /* number of points */ double *x, /* x values */ double *y /* y values */ ) { int i; spearman_rank_t *sx, *sy; //Sorted-x and sorted-y in our struct type. double sumx, sumxsq, sumxy, sumy, sumysq; sumx = sumxsq = sumxy = sumy = sumysq = 0; sx = malloc(n*sizeof(spearman_rank_t)); sy = malloc(n*sizeof(spearman_rank_t)); //Copy into the array of structs and the pointer array for (i=0;idata - ((spearman_rank_t *) b)->data; if (temp > 0) return 1; else if (temp < 0) return -1; else return 0; } static int compare_spearman_rank_t_orig_rank(const void *a, const void *b) { double temp = ((spearman_rank_t *) a)->orig_rank - ((spearman_rank_t *) b)->orig_rank; if (temp > 0) return 1; else if (temp < 0) return -1; else return 0; }