正在加载图片...
14.6 Nonparametric or Rank Correlation 641 holds exactly.Notice that if all the f&'s and all the gm's are equal to one,meaning that there are no ties,then equation (14.6.5)reduces to equation(14.6.4). In(14.6.2)we gave a t-statistic that tests the significance of a nonzero ra.It is also possible to test the significance of D directly.The expectation value of D in the null hypothesis of uncorrelated data sets is D=a3-M-b∑2-)-b∑G2-9a) (14.6.6 its variance is Var(D)= (N-1)N2(N+1)2 36 ∑m(g-gm】 14.6.7) N3-N N3-N from NUMERICAL RECIPES I 18881892 and it is approximately normally distributed,so that the significance level is a complementary error function(cf.equation 14.5.2).Of course,(14.6.2)and (14.6.7) server are not independent tests,but simply variants of the same test.In the program that (Nort follows,we calculate both the significance level obtained by using (14.6.2)and the America computer University Press. THE significance level obtained by using(14.6.7);their discrepancy will give you an idea of how good the approximations are.You will also notice that we break off the task ART of assigning ranks (including tied midranks)into a separate function,crank 9 Programs #include <math.h> #include "nrutil.h" void spear(float datal],float data2],unsigned long n,float *d,float *zd, float tprobd,float *rs,float *probrs) to dir Given two data arrays,data1 [1..n]and data2[1..n],this routine returns their sum-squared difference of ranks as D,the number of standard deviations by which D deviates from its null- hypothesis expected value as zd,the two-sided significance level of this deviation as probd OF SCIENTIFIC COMPUTING(ISBN Spearman's rank correlation rs as rs,and the two-sided significance level of its deviation from 198918920 zero as probrs.The external routines crank(below)and sort2 ($8.2)are used.A small value of either probd or probrs indicates a significant correlation (rs positive)or anticorrelation (rs negative). float betai(float a,float b,float x); void crank(unsigned long n,float w[],float *s); Numerical Recipes 10-621 43108 float erfcc(float x); void sort2(unsigned long n,float arr[],float brr[]); unsigned long j; (outside float vard,t,sg,sf,fac,en3n,en,df,aved,*wksp1,*wksp2; Software. wkspi-vector(1,n); wksp2=vector(1,n); North Amer ying of for (j=1;j<mn;j++){ wksp1[i]=datal[i]; wksp2[j]=data2[j]; sort2(n,wksp1,wksp2); Sort each of the data arrays,and convert the entries to crank(n,wksp1,&sf); ranks.The values sf and sg return the sums >(fi-f) sort2(n,wksp2,wksp1); and (gm-gm),respectively. crank(n,wksp2,&sg); *d=0.0; for (j=1;j<=n;j++) Sum the squared difference of ranks. *d +=SQR(wksp1[j]-wksp2[j]);14.6 Nonparametric or Rank Correlation 641 Permission is granted for internet users to make one paper copy for their own personal use. Further reproduction, or any copyin Copyright (C) 1988-1992 by Cambridge University Press. Programs Copyright (C) 1988-1992 by Numerical Recipes Software. Sample page from NUMERICAL RECIPES IN C: THE ART OF SCIENTIFIC COMPUTING (ISBN 0-521-43108-5) g of machine￾readable files (including this one) to any server computer, is strictly prohibited. To order Numerical Recipes books or CDROMs, visit website http://www.nr.com or call 1-800-872-7423 (North America only), or send email to directcustserv@cambridge.org (outside North America). holds exactly. Notice that if all the fk’s and all the gm’s are equal to one, meaning that there are no ties, then equation (14.6.5) reduces to equation (14.6.4). In (14.6.2) we gave a t-statistic that tests the significance of a nonzero r s. It is also possible to test the significance of D directly. The expectation value of D in the null hypothesis of uncorrelated data sets is D = 1 6 (N3 − N) − 1 12  k (f 3 k − fk) − 1 12  m (g3 m − gm) (14.6.6) its variance is Var(D) = (N − 1)N2(N + 1)2 36 × 1 −  k(f 3 k − fk) N3 − N 1 −  m(g3 m − gm) N3 − N (14.6.7) and it is approximately normally distributed, so that the significance level is a complementary error function (cf. equation 14.5.2). Of course, (14.6.2) and (14.6.7) are not independent tests, but simply variants of the same test. In the program that follows, we calculate both the significance level obtained by using (14.6.2) and the significance level obtained by using (14.6.7); their discrepancy will give you an idea of how good the approximations are. You will also notice that we break off the task of assigning ranks (including tied midranks) into a separate function, crank. #include <math.h> #include "nrutil.h" void spear(float data1[], float data2[], unsigned long n, float *d, float *zd, float *probd, float *rs, float *probrs) Given two data arrays, data1[1..n] and data2[1..n], this routine returns their sum-squared difference of ranks as D, the number of standard deviations by which D deviates from its null￾hypothesis expected value as zd, the two-sided significance level of this deviation as probd, Spearman’s rank correlation rs as rs, and the two-sided significance level of its deviation from zero as probrs. The external routines crank (below) and sort2 (§8.2) are used. A small value of either probd or probrs indicates a significant correlation (rs positive) or anticorrelation (rs negative). { float betai(float a, float b, float x); void crank(unsigned long n, float w[], float *s); float erfcc(float x); void sort2(unsigned long n, float arr[], float brr[]); unsigned long j; float vard,t,sg,sf,fac,en3n,en,df,aved,*wksp1,*wksp2; wksp1=vector(1,n); wksp2=vector(1,n); for (j=1;j<=n;j++) { wksp1[j]=data1[j]; wksp2[j]=data2[j]; } sort2(n,wksp1,wksp2); Sort each of the data arrays, and convert the entries to ranks. The values sf and sg return the sums (f3 k −fk) and (g3 m − gm), respectively. crank(n,wksp1,&sf); sort2(n,wksp2,wksp1); crank(n,wksp2,&sg); *d=0.0; for (j=1;j<=n;j++) Sum the squared difference of ranks. *d += SQR(wksp1[j]-wksp2[j]);
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有