14.2 Do Two Distributions Have the Same Means or Variances? 615 that this is wasteful,since it yields much more information than just the median (e.g.,the upper and lower quartile points,the deciles,etc.).In fact,we saw in 88.5 that the element (N+1)/2 can be located in of order N operations.Consult that section for routines. The mode of a probability distribution function p(x)is the value of x where it takes on a maximum value.The mode is useful primarily when there is a single,sharp maximum.in which case it estimates the central value.Occasionally,a distribution will be bimodal.with two relative maxima;then one may wish to know the two modes individually.Note that,in such cases,the mean and median are not very useful,since they will give only a"compromise"value between the two peaks. CITED REFERENCES AND FURTHER READING: Bevington,PR.1969.Data Reduction and Error Analysis for the Physical Sciences (New York: 茶 McGraw-Hill),Chapter 2. Stuart,A.,and Ord,J.K.1987,Kendall's Advanced Theory of Statistics,5th ed.(London:Griffin and Co.)[previous eds.published as Kendall,M.,and Stuart,A.,The Advanced Theory of Statistics].vol.1.$10.15 Norusis,M.J.1982.SPSS Introductory Guide:Basic Statistics and Operations:and 1985,SPSS- X Advanced Statistics Guide (New York:McGraw-Hill). 9 Chan,T.F.,Golub,G.H.,and LeVeque,R.J.1983,American Statistician,vol.37,pp.242-247.[1] Cramer,H.1946,Mathematical Methods of Statistics (Princeton:Princeton University Press). 515.10.[2 SCIENTIFIC 14.2 Do Two Distributions Have the Same Means or Variances? Not uncommonly we want to know whether two distributions have the same mean.For example,a first set of measured values may have been gathered before some event,a second set after it.We want to know whether the event,a"treatment" or a "change in a control parameter,"made a difference. Our first thought is to ask"how many standard deviations"one sample mean is Numerical Recipes 10621 43106 from the other.That number may in fact be a useful thing to know.It does relate to the strength or"importance"of a difference of means if that difference is genuine. However,by itself,it says nothing about whether the difference is genuine,that is, (outside 腿 statistically significant.A difference of means can be very small compared to the North standard deviation,and yet very significant,if the number of data points is large. Conversely,a difference may be moderately large but not significant,if the data are sparse.We will be meeting these distinct concepts of strength and significance several times in the next few sections. A quantity that measures the significance of a difference of means is not the number of standard deviations that they are apart,but the number of so-called standard errors that they are apart.The standard error of a set of values measures the accuracy with which the sample mean estimates the population(or"true")mean. Typically the standard error is equal to the sample's standard deviation divided by the square root of the number of points in the sample
14.2 Do Two Distributions Have the Same Means or Variances? 615 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 machinereadable 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). that this is wasteful, since it yields much more information than just the median (e.g., the upper and lower quartile points, the deciles, etc.). In fact, we saw in §8.5 that the element x(N+1)/2 can be located in of order N operations. Consult that section for routines. The mode of a probability distribution function p(x) is the value of x where it takes on a maximum value. The mode is useful primarily when there is a single, sharp maximum, in which case it estimates the central value. Occasionally, a distribution will be bimodal, with two relative maxima; then one may wish to know the two modes individually. Note that, in such cases, the mean and median are not very useful, since they will give only a “compromise” value between the two peaks. CITED REFERENCES AND FURTHER READING: Bevington, P.R. 1969, Data Reduction and Error Analysis for the Physical Sciences (New York: McGraw-Hill), Chapter 2. Stuart, A., and Ord, J.K. 1987, Kendall’s Advanced Theory of Statistics, 5th ed. (London: Griffin and Co.) [previous eds. published as Kendall, M., and Stuart, A., The Advanced Theory of Statistics], vol. 1, §10.15 Norusis, M.J. 1982, SPSS Introductory Guide: Basic Statistics and Operations; and 1985, SPSSX Advanced Statistics Guide (New York: McGraw-Hill). Chan, T.F., Golub, G.H., and LeVeque, R.J. 1983, American Statistician, vol. 37, pp. 242–247. [1] Cram´er, H. 1946, Mathematical Methods of Statistics (Princeton: Princeton University Press), §15.10. [2] 14.2 Do Two Distributions Have the Same Means or Variances? Not uncommonly we want to know whether two distributions have the same mean. For example, a first set of measured values may have been gathered before some event, a second set after it. We want to know whether the event, a “treatment” or a “change in a control parameter,” made a difference. Our first thought is to ask “how many standard deviations” one sample mean is from the other. That number may in fact be a useful thing to know. It does relate to the strength or “importance” of a difference of means if that difference is genuine. However, by itself, it says nothing about whether the difference is genuine, that is, statistically significant. A difference of means can be very small compared to the standard deviation, and yet very significant, if the number of data points is large. Conversely, a difference may be moderately large but not significant, if the data are sparse. We will be meeting these distinct concepts of strength and significance several times in the next few sections. A quantity that measures the significance of a difference of means is not the number of standard deviations that they are apart, but the number of so-called standard errors that they are apart. The standard error of a set of values measures the accuracy with which the sample mean estimates the population (or “true”) mean. Typically the standard error is equal to the sample’s standard deviation divided by the square root of the number of points in the sample
616 Chapter 14.Statistical Description of Data Student's t-test for Significantly Different Means Applying the concept of standard error,the conventional statistic for measuring the significance of a difference of means is termed Student's t.When the two distributions are thought to have the same variance,but possibly different means, then Student's t is computed as follows:First,estimate the standard error of the difference of the means,sp,from the"pooled variance"by the formula CeA(c:-EA2+∑eB(1-B2 SD (14.2.1) NA+NB-2 NB where each sum is over the points in one sample,the first or second,each mean likewise refers to one sample or the other,and NA and NB are the numbers of points 套 in the first and second samples,respectively.Second,compute t by t=工A-B (14.2.2) 令 SD Third.evaluate the significance of this value of t for Student's distribution with Press. NA+NB -2 degrees of freedom,by equations (6.4.7)and(6.4.9),and by the routine betai (incomplete beta function)of 86.4. The significance is a number between zero and one,and is the probability that t could be this large or larger just by chance,for distributions with equal means. Therefore,a small numerical value of the significance(0.05 or 0.01)means that the SCIENTIFIC observed difference is "very significant."The function A(t)in equation(6.4.7) 6 is one minus the significance As a routine,we have #include 1920 COMPUTING (ISBN void ttest(float datal[],unsigned long n1,float data2[],unsigned long n2, float *t,float *prob) 10.621 Given the arrays data1[1..n1]and data2[1..n2],this routine returns Student's t as t, Numerica and its significance as prob,small values of prob indicating that the arrays have significantly uction Recipes 43108 different means.The data arrays are assumed to be drawn from populations with the same true variance. (outside void avevar(float data[],unsigned long n,float *ave,float *var); float betai(float a,float b,float x); Software. float var1,var2,svar,df,ave1,ave2; North ying of avevar(datal,n1,&ave1,&var1); avevar(data2,n2,&ave2,&var2); df=n1+n2-2; Degrees of freedom. svar=((n1-1)*var1+(n2-1)*var2)/df; Pooled variance. *t=(ave1-ave2)/sgrt(svar*(1.0/n1+1.0/n2)) *prob=betai(0.5*df,0.5,df/(df+(*t)(*t))); See equation (6.4.9). which makes use of the following routine for computing the mean and variance of a set of numbers
616 Chapter 14. Statistical Description of Data 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 machinereadable 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). Student’s t-test for Significantly Different Means Applying the concept of standard error, the conventional statistic for measuring the significance of a difference of means is termed Student’s t. When the two distributions are thought to have the same variance, but possibly different means, then Student’s t is computed as follows: First, estimate the standard error of the difference of the means, sD, from the “pooled variance” by the formula sD = i∈A(xi − xA)2 + i∈B(xi − xB)2 NA + NB − 2 1 NA + 1 NB (14.2.1) where each sum is over the points in one sample, the first or second, each mean likewise refers to one sample or the other, and NA and NB are the numbers of points in the first and second samples, respectively. Second, compute t by t = xA − xB sD (14.2.2) Third, evaluate the significance of this value of t for Student’s distribution with NA + NB − 2 degrees of freedom, by equations (6.4.7) and (6.4.9), and by the routine betai (incomplete beta function) of §6.4. The significance is a number between zero and one, and is the probability that |t| could be this large or larger just by chance, for distributions with equal means. Therefore, a small numerical value of the significance (0.05 or 0.01) means that the observed difference is “very significant.” The function A(t|ν) in equation (6.4.7) is one minus the significance. As a routine, we have #include void ttest(float data1[], unsigned long n1, float data2[], unsigned long n2, float *t, float *prob) Given the arrays data1[1..n1] and data2[1..n2], this routine returns Student’s t as t, and its significance as prob, small values of prob indicating that the arrays have significantly different means. The data arrays are assumed to be drawn from populations with the same true variance. { void avevar(float data[], unsigned long n, float *ave, float *var); float betai(float a, float b, float x); float var1,var2,svar,df,ave1,ave2; avevar(data1,n1,&ave1,&var1); avevar(data2,n2,&ave2,&var2); df=n1+n2-2; Degrees of freedom. svar=((n1-1)*var1+(n2-1)*var2)/df; Pooled variance. *t=(ave1-ave2)/sqrt(svar*(1.0/n1+1.0/n2)); *prob=betai(0.5*df,0.5,df/(df+(*t)*(*t))); See equation (6.4.9). } which makes use of the following routine for computing the mean and variance of a set of numbers,
14.2 Do Two Distributions Have the Same Means or Variances? 617 void avevar(float data[],unsigned long n,float tave,float *var) Given array data[1..n],returns its mean as ave and its variance as var. unsigned long j; float s,ep; for (*ave=0.0,j=1;j #include "nrutil.h" void tutest(float datal[],unsigned long n1,float data2[],unsigned long n2, float *t,float *prob) Given the arrays data1[1..n1]and data2[1..n2],this routine returns Student's tas t.and its significance as prob,small values of prob indicating that the arrays have significantly differ- ent means.The data arrays are allowed to be drawn from populations with unequal variances. void avevar(float data,unsigned long n,float *ave,float *var); float betai(float a,float b,float x); float vari,var2,df,avel,ave2;
14.2 Do Two Distributions Have the Same Means or Variances? 617 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 machinereadable 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). void avevar(float data[], unsigned long n, float *ave, float *var) Given array data[1..n], returns its mean as ave and its variance as var. { unsigned long j; float s,ep; for (*ave=0.0,j=1;j #include "nrutil.h" void tutest(float data1[], unsigned long n1, float data2[], unsigned long n2, float *t, float *prob) Given the arrays data1[1..n1] and data2[1..n2], this routine returns Student’s t as t, and its significance as prob, small values of prob indicating that the arrays have significantly different means. The data arrays are allowed to be drawn from populations with unequal variances. { void avevar(float data[], unsigned long n, float *ave, float *var); float betai(float a, float b, float x); float var1,var2,df,ave1,ave2;
618 Chapter 14.Statistical Description of Data avevar(datal,n1,&ave1,&var1); avevar(data2,n2,&ave2,&var2); *t=(ave1-ave2)/sqrt(var1/n1+var2/n2); df=SQR(var1/n1+var2/n2)/(SQR(var1/n1)/(n1-1)+SQR(var2/n2)/(n2-1)); *prob=betai(0.5*df,0.5,df/(df+SQR(*t))); Our final example of a Student's t test is the case of paired samples.Here we imagine that much of the variance in both samples is due to effects that are point-by-point identical in the two samples.For example,we might have two job candidates who have each been rated by the same ten members of a hiring committee. We want to know if the means of the ten scores differ significantly.We first try ttest above,and obtain a value of prob that is not especially significant (e.g., nted for >0.05).But perhaps the significance is being washed out by the tendency of some committee members always to give high scores,others always to give low scores, which increases the apparent variance and thus decreases the significance of any difference in the means.We thus try the paired-sample formulas, 1 Cov(A,B)N-1 >(Ai-A)(B:-TB) (14.2.5) 应@ 9 i1 Var(A)+Var(B)-2Cov(A:ZB) 1/2 SD= (14.2.6) N ts 工A-EB 9 (14.2.7) SD where N is the number in each sample (number of pairs).Notice that it is important SCIENTIFIC that a particular value of i label the corresponding points in each sample,that is, the ones that are paired.The significance of the t statistic in(14.2.7)is evaluated 6 for N-1 degrees of freedom. The routine is COMPUTING (ISBN 188810920 #include void tptest(float datal,float data2[],unsigned long n,float *t, float *prob) Given the paired arrays data1[1..n]and data2[1..n],this routine returns Student's t for uurggoglrion Numerical Recipes 10-621 43108 paired data as t,and its significance as prob,small values of prob indicating a significant difference of means. (outside void avevar(float data,unsigned long n,float *ave,float *var); float betai(float a,float b,float x); Software. unsigned long j; float var1,var2,avel,ave2,sd,df,cov=0.0; avevar(datal,n,&ave1,&var1); avevar(data2,n,&ave2,&var2); for(j=1:j<=n;j++) cov +=(datal[i]-ave1)*(data2[i]-ave2); cov /df=n-1; sd=sqrt ((var1+var2-2.0*cov)/n); *t=(avel-ave2)/sd: *prob=betai(0.5*df,0.5,df/(df+(*t)*(*t)));
618 Chapter 14. Statistical Description of Data 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 machinereadable 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). avevar(data1,n1,&ave1,&var1); avevar(data2,n2,&ave2,&var2); *t=(ave1-ave2)/sqrt(var1/n1+var2/n2); df=SQR(var1/n1+var2/n2)/(SQR(var1/n1)/(n1-1)+SQR(var2/n2)/(n2-1)); *prob=betai(0.5*df,0.5,df/(df+SQR(*t))); } Our final example of a Student’s t test is the case of paired samples. Here we imagine that much of the variance in both samples is due to effects that are point-by-point identical in the two samples. For example, we might have two job candidates who have each been rated by the same ten members of a hiring committee. We want to know if the means of the ten scores differ significantly. We first try ttest above, and obtain a value of prob that is not especially significant (e.g., > 0.05). But perhaps the significance is being washed out by the tendency of some committee members always to give high scores, others always to give low scores, which increases the apparent variance and thus decreases the significance of any difference in the means. We thus try the paired-sample formulas, Cov(xA, xB) ≡ 1 N − 1 N i=1 (xAi − xA)(xBi − xB) (14.2.5) sD = Var(xA) + Var(xB) − 2Cov(xA, xB) N 1/2 (14.2.6) t = xA − xB sD (14.2.7) where N is the number in each sample (number of pairs). Notice that it is important that a particular value of i label the corresponding points in each sample, that is, the ones that are paired. The significance of the t statistic in (14.2.7) is evaluated for N − 1 degrees of freedom. The routine is #include void tptest(float data1[], float data2[], unsigned long n, float *t, float *prob) Given the paired arrays data1[1..n] and data2[1..n], this routine returns Student’s t for paired data as t, and its significance as prob, small values of prob indicating a significant difference of means. { void avevar(float data[], unsigned long n, float *ave, float *var); float betai(float a, float b, float x); unsigned long j; float var1,var2,ave1,ave2,sd,df,cov=0.0; avevar(data1,n,&ave1,&var1); avevar(data2,n,&ave2,&var2); for (j=1;j<=n;j++) cov += (data1[j]-ave1)*(data2[j]-ave2); cov /= df=n-1; sd=sqrt((var1+var2-2.0*cov)/n); *t=(ave1-ave2)/sd; *prob=betai(0.5*df,0.5,df/(df+(*t)*(*t))); }
14.2 Do Two Distributions Have the Same Means or Variances? 619 F-Test for Significantly Different Variances The F-test tests the hypothesis that two samples have different variances by trying to reject the null hypothesis that their variances are actually consistent.The statistic F is the ratio of one variance to the other.so values either1 or1 will indicate very significant differences.The distribution of F in the null case is given in equation(6.4.11),which is evaluated using the routine betai.In the most common case,we are willing to disprove the null hypothesis(of equal variances)by either very large or very small values of F,so the correct significance is fwo-tailed, the sum of two incomplete beta functions.It turns out,by equation(6.4.3),that the two tails are always equal;we need compute only one,and double it.Occasionally, when the null hypothesis is strongly viable,the identity of the two tails can become nted for confused,giving an indicated probability greater than one.Changing the probability to two minus itself correctly exchanges the tails.These considerations and equation (6.4.3)give the routine void ftest(float datal[],unsigned long n1,float data2[],unsigned long n2, float *f,float *prob) (Nort server 令 Given the arrays data1[1..n1]and data2[1..n2],this routine returns the value of f,and its significance as prob.Small values of prob indicate that the two arrays have significantly different variances. 三4ad THE ART void avevar(float data[],unsigned long n,float *ave,float *var); float betai(float a,float b,float x); 9 float varl,var2,avel,ave2,df1,df2; Progra avevar(datal,n1,&avel,&var1): avevar(data2,n2,&ave2,&var2); if (var1 var2){ Make F the ratio of the larger variance to the smaller *f=var1/var2; one. df1=n1-1; df2=n2-1; else OF SCIENTIFIC COMPUTING(ISBN *f=var2/var1; df1n2-1; df2=n1-1; 10-:6211 *prob=2.0*betai(0.5*df2,0.5*df1,df2/(df2+df1*(*f))); if (*prob 1.0)*prob=2.0-*prob; v@cambridge.org Numerical Recipes books or 1988-1992 by Numerical Recipes 43108 (outside North Software. CITED REFERENCES AND FURTHER READING: Ame von Mises,R.1964,Mathematical Theory of Probability and Statistics (New York:Academic Press),Chapter IX(B). Norusis,M.J.1982,SPSS Introductory Guide:Basic Statistics and Operations;and 1985,SPSS- X Advanced Statistics Guide (New York:McGraw-Hill)
14.2 Do Two Distributions Have the Same Means or Variances? 619 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 machinereadable 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). F-Test for Significantly Different Variances The F-test tests the hypothesis that two samples have different variances by trying to reject the null hypothesis that their variances are actually consistent. The statistic F is the ratio of one variance to the other, so values either 1 or 1 will indicate very significant differences. The distribution of F in the null case is given in equation (6.4.11), which is evaluated using the routine betai. In the most common case, we are willing to disprove the null hypothesis (of equal variances) by either very large or very small values of F, so the correct significance is two-tailed, the sum of two incomplete beta functions. It turns out, by equation (6.4.3), that the two tails are always equal; we need compute only one, and double it. Occasionally, when the null hypothesis is strongly viable, the identity of the two tails can become confused, giving an indicated probability greater than one. Changing the probability to two minus itself correctly exchanges the tails. These considerations and equation (6.4.3) give the routine void ftest(float data1[], unsigned long n1, float data2[], unsigned long n2, float *f, float *prob) Given the arrays data1[1..n1] and data2[1..n2], this routine returns the value of f, and its significance as prob. Small values of prob indicate that the two arrays have significantly different variances. { void avevar(float data[], unsigned long n, float *ave, float *var); float betai(float a, float b, float x); float var1,var2,ave1,ave2,df1,df2; avevar(data1,n1,&ave1,&var1); avevar(data2,n2,&ave2,&var2); if (var1 > var2) { Make F the ratio of the larger variance to the smaller *f=var1/var2; one. df1=n1-1; df2=n2-1; } else { *f=var2/var1; df1=n2-1; df2=n1-1; } *prob = 2.0*betai(0.5*df2,0.5*df1,df2/(df2+df1*(*f))); if (*prob > 1.0) *prob=2.0-*prob; } CITED REFERENCES AND FURTHER READING: von Mises, R. 1964, Mathematical Theory of Probability and Statistics (New York: Academic Press), Chapter IX(B). Norusis, M.J. 1982, SPSS Introductory Guide: Basic Statistics and Operations; and 1985, SPSSX Advanced Statistics Guide (New York: McGraw-Hill)
620 Chapter 14.Statistical Description of Data 14.3 Are Two Distributions Different? Given two sets of data,we can generalize the questions asked in the previous section and ask the single question:Are the two sets drawn from the same distribution function,or from different distribution functions?Equivalently,in proper statistical language,"Can we disprove,to a certain required level of significance,the null hypothesis that two data sets are drawn from the same population distribution function?"Disproving the null hypothesis in effect proves that the data sets are from different distributions.Failing to disprove the null hypothesis,on the other hand, 三 only shows that the data sets can be consistent with a single distribution function. 81 One can never prove that two data sets come from a single distribution,since (e.g.) no practical amount of data can distinguish between two distributions which differ only by one part in 1010 Proving that two distributions are different,or showing that they are consistent, is a task that comes up all the time in many areas of research:Are the visible stars distributed uniformly in the sky?(That is,is the distribution of stars as a function % of declination-position in the sky-the same as the distribution of sky area as a function of declination?)Are educational patterns the same in Brooklyn as in the 9 Bronx?(That is,are the distributions of people as a function of last-grade-attended the same?)Do two brands of fluorescent lights have the same distribution of burn-out times?Is the incidence of chicken pox the same for first-born,second-born, third-born children,etc.? These four examples illustrate the four combinations arising from two different a之w 9 9 dichotomies:(1)The data are either continuous or binned.(2)Either we wish to compare one data set to a known distribution,or we wish to compare two equally unknown data sets.The data sets on fluorescent lights and on stars are continuous, since we can be given lists of individual burnout times or of stellar positions.The data sets on chicken pox and educational level are binned,since we are given tables of numbers of events in discrete categories:first-born,second-born,etc.;or 6th Grade,7th Grade,etc.Stars and chicken pox,on the other hand,share the property that the null hypothesis is a known distribution(distribution of area in the sky,or incidence of chicken pox in the general population).Fluorescent lights and 10621 educational level involve the comparison of two equally unknown data sets(the two brands,or Brooklyn and the Bronx). One can always turn continuous data into binned data,by grouping the events 43106 into specified ranges of the continuous variable(s):declinations between 0 and 10 degrees,10 and 20,20 and 30,etc.Binning involves a loss of information,however. 腿 Also,there is often considerable arbitrariness as to how the bins should be chosen. North Along with many other investigators,we prefer to avoid unnecessary binning of data. The accepted test for differences between binned distributions is the chi-square test.For continuous data as a function of a single variable,the most generally accepted test is the Kolmogorov-Smirnov test.We consider each in turn. Chi-Square Test Suppose that Ni is the number of events observed in the ith bin,and that ni is the number expected according to some known distribution.Note that the Ni's are
620 Chapter 14. Statistical Description of Data 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 machinereadable 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). 14.3 Are Two Distributions Different? Given two sets of data, we can generalize the questions asked in the previous section and ask the single question: Are the two sets drawn from the same distribution function, or from different distribution functions? Equivalently, in proper statistical language, “Can we disprove, to a certain required level of significance, the null hypothesis that two data sets are drawn from the same population distribution function?” Disproving the null hypothesis in effect proves that the data sets are from different distributions. Failing to disprove the null hypothesis, on the other hand, only shows that the data sets can be consistent with a single distribution function. One can never prove that two data sets come from a single distribution, since (e.g.) no practical amount of data can distinguish between two distributions which differ only by one part in 1010. Proving that two distributions are different, or showing that they are consistent, is a task that comes up all the time in many areas of research: Are the visible stars distributed uniformly in the sky? (That is, is the distribution of stars as a function of declination — position in the sky — the same as the distribution of sky area as a function of declination?) Are educational patterns the same in Brooklyn as in the Bronx? (That is, are the distributions of people as a function of last-grade-attended the same?) Do two brands of fluorescent lights have the same distribution of burn-out times? Is the incidence of chicken pox the same for first-born, second-born, third-born children, etc.? These four examples illustrate the four combinations arising from two different dichotomies: (1) The data are either continuous or binned. (2) Either we wish to compare one data set to a known distribution, or we wish to compare two equally unknown data sets. The data sets on fluorescent lights and on stars are continuous, since we can be given lists of individual burnout times or of stellar positions. The data sets on chicken pox and educational level are binned, since we are given tables of numbers of events in discrete categories: first-born, second-born, etc.; or 6th Grade, 7th Grade, etc. Stars and chicken pox, on the other hand, share the property that the null hypothesis is a known distribution (distribution of area in the sky, or incidence of chicken pox in the general population). Fluorescent lights and educational level involve the comparison of two equally unknown data sets (the two brands, or Brooklyn and the Bronx). One can always turn continuous data into binned data, by grouping the events into specified ranges of the continuous variable(s): declinations between 0 and 10 degrees, 10 and 20, 20 and 30, etc. Binning involves a loss of information, however. Also, there is often considerable arbitrariness as to how the bins should be chosen. Along with many other investigators, we prefer to avoid unnecessary binning of data. The accepted test for differences between binned distributions is the chi-square test. For continuous data as a function of a single variable, the most generally accepted test is the Kolmogorov-Smirnov test. We consider each in turn. Chi-Square Test Suppose that Ni is the number of events observed in the ith bin, and that ni is the number expected according to some known distribution. Note that the N i’s are