Perform the Kolmogorov-Smirnov test for two sets of samples.
More...
#include "mdb.h"
#include "sort.h"
Go to the source code of this file.
|
double | twoVariableKStest (double *d1, long n1, double *d2, long n2, double *maxCDFerror) |
|
double | KS_Qfunction (double lambda) |
| Compute the Q-function for the Kolmogorov-Smirnov test.
|
|
Perform the Kolmogorov-Smirnov test for two sets of samples.
- Copyright
- (c) 2002 The University of Chicago, as Operator of Argonne National Laboratory.
- (c) 2002 The Regents of the University of California, as Operator of Los Alamos National Laboratory.
- License
- This file is distributed under the terms of the Software License Agreement found in the file LICENSE included with this distribution.
- Author
- M. Borland, C. Saunders, R. Soliday
Definition in file kstests.c.
◆ KS_Q_ACCURACY
#define KS_Q_ACCURACY 1e-8 |
◆ KS_Q_MAXTERMS
#define KS_Q_MAXTERMS 1000 |
◆ KS_Qfunction()
double KS_Qfunction |
( |
double | lambda | ) |
|
Compute the Q-function for the Kolmogorov-Smirnov test.
Given a lambda value, this function approximates the complementary cumulative distribution function needed to determine the KS probability (Q-value).
- Parameters
-
lambda | The computed KS statistic scaled by sqrt(N). |
- Returns
- The KS Q-value as a probability measure.
Definition at line 57 of file kstests.c.
57 {
58 long j;
59 double expFactor, factor;
60 double sum, term;
61
62 expFactor = -2 * lambda * lambda;
63 factor = 1;
64 j = 1;
65 sum = 0;
66 do {
67 term = exp(expFactor * j * j);
68 sum += factor * term;
69 factor *= -1;
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);
73 return 2 * sum;
74}
◆ twoVariableKStest()
double twoVariableKStest |
( |
double * | d1, |
|
|
long | n1, |
|
|
double * | d2, |
|
|
long | n2, |
|
|
double * | maxCDFerror ) |
Definition at line 19 of file kstests.c.
19 {
20 long i1, i2;
21 double CDFerror, xDifference, CDF1, CDF2, sqrtNe;
22
25 i1 = i2 = 0;
26 CDF1 = CDF2 = 0;
27 *maxCDFerror = 0;
28 while (i1 < n1 && i2 < n2) {
29
30
31
32 if ((xDifference = d1[i1] - d2[i2]) <= 0)
33
34 CDF1 = ++i1 / ((double)n1);
35 if (xDifference >= 0)
36
37 CDF2 = ++i2 / ((double)n2);
38 if ((CDFerror = fabs(CDF1 - CDF2)) > *maxCDFerror)
39 *maxCDFerror = CDFerror;
40 }
41 sqrtNe = sqrt(((double)n1 * n2) / ((double)n1 + n2));
42 return KS_Qfunction((sqrtNe + 0.12 + 0.11 / sqrtNe) * (*maxCDFerror));
43}
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.