The routine may be called by the names g08ccf or nagf_nonpar_test_ks_1sample_user.
3Description
The data consists of a single sample of observations, denoted by . Let and represent the sample cumulative distribution function and the theoretical (null) cumulative distribution function respectively at the point , where is the th smallest sample observation.
The Kolmogorov–Smirnov test provides a test of the null hypothesis : the data are a random sample of observations from a theoretical distribution specified by you (in cdf) against one of the following alternative hypotheses.
(i): the data cannot be considered to be a random sample from the specified null distribution.
(ii): the data arise from a distribution which dominates the specified null distribution. In practical terms, this would be demonstrated if the values of the sample cumulative distribution function tended to exceed the corresponding values of the theoretical cumulative distribution function .
(iii): the data arise from a distribution which is dominated by the specified null distribution. In practical terms, this would be demonstrated if the values of the theoretical cumulative distribution function tended to exceed the corresponding values of the sample cumulative distribution function .
One of the following test statistics is computed depending on the particular alternative hypothesis specified (see the description of the argument ntype in Section 5).
For the alternative hypothesis :
– the largest absolute deviation between the sample cumulative distribution function and the theoretical cumulative distribution function. Formally .
For the alternative hypothesis :
– the largest positive deviation between the sample cumulative distribution function and the theoretical cumulative distribution function. Formally .
For the alternative hypothesis :
– the largest positive deviation between the theoretical cumulative distribution function and the sample cumulative distribution function. Formally . This is only true for continuous distributions. See Section 9 for comments on discrete distributions.
The standardized statistic, , is also computed, where may be or depending on the choice of the alternative hypothesis. This is the standardized value of with no continuity correction applied and the distribution of converges asymptotically to a limiting distribution, first derived by Kolmogorov (1933), and then tabulated by Smirnov (1948). The asymptotic distributions for the one-sided statistics were obtained by Smirnov (1933).
The probability, under the null hypothesis, of obtaining a value of the test statistic as extreme as that observed, is computed. If , an exact method given by Conover (1980) is used. Note that the method used is only exact for continuous theoretical distributions and does not include Conover's modification for discrete distributions. This method computes the one-sided probabilities. The two-sided probabilities are estimated by doubling the one-sided probability. This is a good estimate for small , that is , but it becomes very poor for larger . If then is computed using the Kolmogorov–Smirnov limiting distributions; see Feller (1948), Kendall and Stuart (1973), Kolmogorov (1933), Smirnov (1933) and Smirnov (1948).
4References
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
Kolmogorov A N (1933) Sulla determinazione empirica di una legge di distribuzione Giornale dell' Istituto Italiano degli Attuari4 83–91
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
5Arguments
1: – IntegerInput
On entry: , the number of observations in the sample.
Constraint:
.
2: – Real (Kind=nag_wp) arrayInput
On entry: the sample observations, .
3: – real (Kind=nag_wp) Function, supplied by the user.External Procedure
cdf must return the value of the theoretical (null) cumulative distribution function for a given value of its argument.
On entry: the argument for which cdf must be evaluated.
cdf must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which g08ccf is called. Arguments denoted as Input must not be changed by this procedure.
Note:cdf should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by g08ccf. If your code inadvertently does return any NaNs or infinities, g08ccf is likely to produce unexpected results.
Constraint:
must always return a value in the range and cdf must always satify the condition that for any .
4: – IntegerInput
On entry: the statistic to be calculated, i.e., the choice of alternative hypothesis.
Computes , to test against .
Computes , to test against .
Computes , to test against .
Constraint:
, or .
5: – Real (Kind=nag_wp)Output
On exit: the Kolmogorov–Smirnov test statistic (, or according to the value of ntype).
6: – Real (Kind=nag_wp)Output
On exit: a standardized value, , of the test statistic, , without the continuity correction applied.
7: – Real (Kind=nag_wp)Output
On exit: the probability, , associated with the observed value of , where may , or depending on the value of ntype (see Section 3).
8: – Real (Kind=nag_wp) arrayOutput
On exit: the sample observations, , sorted in ascending order.
9: – IntegerInput/Output
On entry: ifail must be set to , or to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of means that an error message is printed while a value of means that it is not.
If halting is not appropriate, the value or is recommended. If message printing is undesirable, then the value is recommended. Otherwise, the value is recommended. When the value or 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).
6Error 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, .
Constraint: .
On entry, .
Constraint: , or .
On entry, at , .
Constraint: , where is supplied in cdf.
On entry, at , and at ,
Constraint: when , , where is supplied in cdf.
An unexpected error has been triggered by this routine. Please
contact NAG.
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.
7Accuracy
For most cases the approximation for given when has a relative error of less than . The two-sided probability is approximated by doubling the one-sided probability. This is only good for small , that is , but very poor for large . The error is always on the conservative side.
8Parallelism and Performance
g08ccf 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.
9Further Comments
The time taken by g08ccf increases with until at which point it drops and then increases slowly.
For a discrete theoretical cumulative distribution function , . Thus if you wish to provide a discrete distribution function the following adjustment needs to be made,
for , return as as usual;
for , return at where is the discrete jump in the distribution. For example for the Poisson or binomial distributions.
10Example
The following example performs the one sample Kolmogorov–Smirnov test to test whether a sample of observations arise firstly from a uniform distribution or secondly from a Normal distribution with mean and standard deviation . The two-sided test statistic, , the standardized test statistic, , and the upper tail probability, , are computed and then printed for each test.