19double twoVariableKStest(
double *d1,
long n1,
double *d2,
long n2,
double *maxCDFerror) {
21 double CDFerror, xDifference, CDF1, CDF2, sqrtNe;
28 while (i1 < n1 && i2 < n2) {
32 if ((xDifference = d1[i1] - d2[i2]) <= 0)
34 CDF1 = ++i1 / ((double)n1);
37 CDF2 = ++i2 / ((double)n2);
38 if ((CDFerror = fabs(CDF1 - CDF2)) > *maxCDFerror)
39 *maxCDFerror = CDFerror;
41 sqrtNe = sqrt(((
double)n1 * n2) / ((
double)n1 + n2));
42 return KS_Qfunction((sqrtNe + 0.12 + 0.11 / sqrtNe) * (*maxCDFerror));
45#define KS_Q_ACCURACY 1e-8
46#define KS_Q_MAXTERMS 1000
59 double expFactor, factor;
62 expFactor = -2 * lambda * lambda;
67 term = exp(expFactor * j * j);
70 }
while (term > KS_Q_ACCURACY && j++ < KS_Q_MAXTERMS);
71 if (j > KS_Q_MAXTERMS)
72 fputs(
"warning: KS test did not converge\n", stderr);
double KS_Qfunction(double lambda)
Compute the Q-function for the Kolmogorov-Smirnov test.
int double_cmpasc(const void *a, const void *b)
Compare two doubles in ascending order.