408409410411412413414415416417418
dt=max(abs(fo-ff),abs(fn-ff)); if (dt > d.val) d.val=dt; fo=fn; } en=sqrt(en); prob.val=ks.qks((en+0.12+0.11/en)*d.val); } /** Given an array data1[0..n1-1], and an array data2[0..n2-1], this routine returns the K-S statistic d and the p-value prob for the null hypothesis that the data sets are drawn from the same
440441442443444445446447448449450
fn2=++j2/en2; while (j2 < n2 && d2 == data2[j2]); if ((dt=abs(fn2-fn1)) > d.val) d.val=dt; } en=sqrt(en1*en2/(en1+en2)); prob.val=ks.qks((en+0.12+0.11/en)*d.val); } /* Given an origin (x, y), and an array of nn points with coordinatesssss xx[0..nn-1] and yy[0..nn-1], count how many of them are in each quadrant around the origin, ad return the normalized fractions.
516517518519520521522523524525526
d1.val=max(d1.val,abs(fd.val-gd.val)); } pearsn(x1,y1,r1,dum,dumm); sqen=sqrt(n1); rr=sqrt(1.0-r1.val*r1.val); prob.val=ks.qks(d1.val*sqen/(1.0+rr*(0.25-0.75/sqen))); } /* Two-dimensional Kolmogorov-Smirnov test on two samples. Given the x and y coordinates of the first
579580581582583584585586
d.val=0.5*(d1+d2); sqen=sqrt(n1*n2/(n1+n2)); pearsn(x1,y1,r1,dum,dumm); pearsn(x2,y2,r2,dum,dumm); rr=sqrt(1.0-0.5*(r1.val*r1.val+r2.val*r2.val)); prob.val=ks.qks(d.val*sqen/(1.0+rr*(0.25-0.75/sqen))); } }
5960616263646566676869
if (localflag) { fail("*** KSdist: Special case #1 failed for Pks"); } localflag = abs(norm.qks(z)-1.0) > sbeps; globalflag = globalflag || localflag; if (localflag) { fail("*** KSdist: Special case #1 failed for Qks"); }
7576777879808182838485
if (localflag) { fail("*** KSdist: Special case #2 failed for Pks"); } localflag = abs(norm.qks(z)-2.0*exp(-2.0)+2.0*exp(-8.0)-2.0*exp(-18.0)) > sbeps; globalflag = globalflag || localflag; if (localflag) { fail("*** KSdist: Special case #2 failed for Qks"); }
90919293949596979899100
if (localflag) { fail("*** KSdist: Special case #3 failed for Pks"); } localflag = abs(norm.qks(z)-0.0) > sbeps; globalflag = globalflag || localflag; if (localflag) { fail("*** KSdist: Special case #3 failed for Qks"); }
100101102103104105106107108109110
} // Pks correctly related to Qks localflag=false; for (i=0;i<N;i++) localflag = localflag || 1.0-norm.pks(x[i])-norm.qks(x[i]) > sbeps; globalflag = globalflag || localflag; if (localflag) { fail("*** KSdist: Pks and Qks do not add to 1.0 in all cases"); }
131132133134135136137138139140141
// inverse of Qks agrees with Qks localflag=false; sbeps=5.e-10; for (i=0;i<1000;i++) { z=0.3+3.0*myran.doub(); a=norm.qks(z); b=norm.invqks(a); // if (abs(z-b) > sbeps) { // System.out.printf(setprecision(15) << z << " %f\n", b << " %f\n", abs(z-b)); // } localflag = localflag || abs(z-b) > sbeps;
161162163164165166167168169170171
} // Fingerprint test for Qks sbeps=1.e-15; for (i=0;i<N;i++) { qks[i]=norm.qks(x[i]); // System.out.printf(setprecision(17) << qks[i]); } // System.out.println("KSdist: Maximum discrepancy = %f\n", maxel(vecsub(qks,qksexp))); localflag = maxel(vecsub(qks,qksexp)) > sbeps; globalflag = globalflag || localflag;