NAG Library Routine Document
G08CDF
1 Purpose
G08CDF performs the two sample Kolmogorov–Smirnov distribution test.
2 Specification
SUBROUTINE G08CDF ( |
N1, X, N2, Y, NTYPE, D, Z, P, SX, SY, IFAIL) |
INTEGER |
N1, N2, NTYPE, IFAIL |
REAL (KIND=nag_wp) |
X(N1), Y(N2), D, Z, P, SX(N1), SY(N2) |
|
3 Description
The data consists of two independent samples, one of size , denoted by , and the other of size denoted by . Let and represent their respective, unknown, distribution functions. Also let and denote the values of the sample cumulative distribution functions at the point for the two samples respectively.
The Kolmogorov–Smirnov test provides a test of the null hypothesis
:
against one of the following alternative hypotheses:
(i) |
: . |
(ii) |
: . This alternative hypothesis is sometimes stated as, ‘The 's tend to be smaller than the 's’, i.e., it would be demonstrated in practical terms if the values of tended to exceed the corresponding values of . |
(iii) |
: . This alternative hypothesis is sometimes stated as, ‘The 's tend to be larger than the 's’, i.e., it would be demonstrated in practical terms if the values of tended to exceed the corresponding values of . |
One of the following test statistics is computed depending on the particular alternative null hypothesis specified (see the description of the parameter
NTYPE in
Section 5).
For the alternative hypothesis
.
- – the largest absolute deviation between the two sample cumulative distribution functions.
For the alternative hypothesis
.
- – the largest positive deviation between the sample cumulative distribution function of the first sample, , and the sample cumulative distribution function of the second sample, . Formally .
For the alternative hypothesis
.
- – the largest positive deviation between the sample cumulative distribution function of the second sample, , and the sample cumulative distribution function of the first sample, . Formally .
G08CDF also returns the standardized statistic
, where
may be
,
or
depending on the choice of the alternative hypothesis. The distribution of this statistic converges asymptotically to a distribution given by Smirnov as
and
increase; see
Feller (1948),
Kendall and Stuart (1973),
Kim and Jenrich (1973),
Smirnov (1933) or
Smirnov (1948).
The probability, under the null hypothesis, of obtaining a value of the test statistic as extreme as that observed, is computed. If
and
then an exact method given by Kim and Jenrich (see
Kim and Jenrich (1973)) is used. Otherwise
is computed using the approximations suggested by
Kim and Jenrich (1973). Note that the method used is only exact for continuous theoretical distributions. This method computes the two-sided probability. The one-sided probabilities are estimated by halving the two-sided probability. This is a good estimate for small
, that is
, but it becomes very poor for larger
.
4 References
Conover W J (1980) Practical Nonparametric Statistics Wiley
Feller W (1948) On the Kolmogorov–Smirnov limit theorems for empirical distributions Ann. Math. Statist. 19 179–181
Kendall M G and Stuart A (1973) The Advanced Theory of Statistics (Volume 2) (3rd Edition) Griffin
Kim P J and Jenrich R I (1973) Tables of exact sampling distribution of the two sample Kolmogorov–Smirnov criterion Selected Tables in Mathematical Statistics 1 80–129 American Mathematical Society
Siegel S (1956) Non-parametric Statistics for the Behavioral Sciences McGraw–Hill
Smirnov N (1933) Estimate of deviation between empirical distribution functions in two independent samples Bull. Moscow Univ. 2(2) 3–16
Smirnov N (1948) Table for estimating the goodness of fit of empirical distributions Ann. Math. Statist. 19 279–281
5 Parameters
- 1: – INTEGERInput
-
On entry: the number of observations in the first sample, .
Constraint:
.
- 2: – REAL (KIND=nag_wp) arrayInput
-
On entry: the observations from the first sample, .
- 3: – INTEGERInput
-
On entry: the number of observations in the second sample, .
Constraint:
.
- 4: – REAL (KIND=nag_wp) arrayInput
-
On entry: the observations from the second sample, .
- 5: – INTEGERInput
-
On entry: the statistic to be computed, i.e., the choice of alternative hypothesis.
- Computes , to test against .
- Computes , to test against .
- Computes , to test against .
Constraint:
, or .
- 6: – REAL (KIND=nag_wp)Output
-
On exit: the Kolmogorov–Smirnov test statistic (
,
or
according to the value of
NTYPE).
- 7: – REAL (KIND=nag_wp)Output
-
On exit: a standardized value, , of the test statistic, , without any correction for continuity.
- 8: – REAL (KIND=nag_wp)Output
-
On exit: the tail probability associated with the observed value of
, where
may be
or
depending on the value of
NTYPE (see
Section 3).
- 9: – REAL (KIND=nag_wp) arrayOutput
-
On exit: the observations from the first sample sorted in ascending order.
- 10: – REAL (KIND=nag_wp) arrayOutput
-
On exit: the observations from the second sample sorted in ascending order.
- 11: – INTEGERInput/Output
-
On entry:
IFAIL must be set to
,
. If you are unfamiliar with this parameter you should refer to
Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value
is recommended. If the output of error messages is undesirable, then the value
is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is
.
When the value is used it is essential to test the value of IFAIL on exit.
On exit:
unless the routine detects an error or a warning has been flagged (see
Section 6).
6 Error Indicators and Warnings
If on entry
or
, explanatory error messages are output on the current error message unit (as defined by
X04AAF).
Errors or warnings detected by the routine:
-
-
On entry, | , or . |
-
The iterative procedure used in the approximation of the probability for large and did not converge. For the two-sided test, is returned. For the one-sided test, is returned.
An unexpected error has been triggered by this routine. Please
contact
NAG.
See
Section 3.8 in the Essential Introduction for further information.
Your licence key may have expired or may not have been installed correctly.
See
Section 3.7 in the Essential Introduction for further information.
Dynamic memory allocation failed.
See
Section 3.6 in the Essential Introduction for further information.
7 Accuracy
The large sample distributions used as approximations to the exact distribution should have a relative error of less than 5% for most cases.
8 Parallelism and Performance
G08CDF is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
Please consult the
X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the
Users' Note for your implementation for any additional implementation-specific information.
The time taken by G08CDF increases with and , until or . At this point one of the approximations is used and the time decreases significantly. The time then increases again modestly with and .
10 Example
This example computes the two-sided Kolmogorov–Smirnov test statistic for two independent samples of size and respectively. The first sample is from a uniform distribution . The second sample is from a uniform distribution . The test statistic, , the standardized test statistic, , and the tail probability, , are computed and printed.
10.1 Program Text
Program Text (g08cdfe.f90)
10.2 Program Data
Program Data (g08cdfe.d)
10.3 Program Results
Program Results (g08cdfe.r)