home *** CD-ROM | disk | FTP | other *** search
- stsper (n,a,b,r)
-
- /*this subroutine computes the spearman rank correlation*/
- /*coefficient for two series of data.*/
-
- int n;
- float a[],b[],*r;
-
- {
-
- int i,j,k,n1,j1,k1,kk,kp;
- float en,z,t,suma2,sumb2,sumab,s;
- extern double sqrt();
-
- en = n;
- kp = 0;
- n1 = n - 1;
- *r = 0.0;
- if (n <= 1) return;
- l5: sort2 (a,b,n);
- k = 1;
-
- for (i = 1; i <= n1; i++)
- {
-
- for (j = k+1; j <= n; j++)
- {
- if (a[k-1] != a[j-1]) goto b1;
- }
-
- b1: z = (k + j-1)*0.5;
- k1 = j-1;
-
- for (kk = k; kk <= k1; kk++)
- a[kk-1] = z;
-
- if (j == n) a[n-1] = en;
- k = j;
- if (j >= n) break;
- }
-
- if (kp != 1)
- {
- for (i = 0; i <= n-1; i++)
- {
- t = a[i];
- a[i] = b[i];
- b[i] = i + 1;
- }
-
- kp = 1;
- goto l5;
- }
- suma2 = sumb2 = sumab = 0.0;
-
- for (i = 0; i <= n-1; i++)
- {
- suma2 = suma2 + a[i]*a[i];
- sumb2 = sumb2 + b[i]*b[i];
- sumab = sumab + a[i]*b[i];
- }
-
- s = en*(en + 1.0);
- s = s*s*0.25;
- *r = (en * suma2 - s) * (en * sumb2 - s);
- if (*r == 0.0) return;
- t = *r;
- *r = (en * sumab - s)/sqrt(t);
-
- }