naginterfaces.library.nonpar.test_ks_2sample¶
- naginterfaces.library.nonpar.test_ks_2sample(x, y, ntype)[source]¶
test_ks_2sample
performs the two sample Kolmogorov–Smirnov distribution test.For full information please refer to the NAG Library document for g08cd
https://support.nag.com/numeric/nl/nagdoc_30.3/flhtml/g08/g08cdf.html
- Parameters
- xfloat, array-like, shape
The observations from the first sample, .
- yfloat, array-like, shape
The observations from the second sample, .
- ntypeint
The statistic to be computed, i.e., the choice of alternative hypothesis.
Computes , to test against .
Computes , to test against .
Computes , to test against .
- Returns
- dfloat
The Kolmogorov–Smirnov test statistic (, or according to the value of ).
- zfloat
A standardized value, , of the test statistic, , without any correction for continuity.
- pfloat
The tail probability associated with the observed value of , where may be or depending on the value of (see Notes).
- sxfloat, ndarray, shape
The observations from the first sample sorted in ascending order.
- syfloat, ndarray, shape
The observations from the second sample sorted in ascending order.
- Raises
- NagValueError
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, .
Constraint: , or .
- Warns
- NagAlgorithmicWarning
- (errno )
The iterative process 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.
- Notes
In the NAG Library the traditional C interface for this routine uses a different algorithmic base. Please contact NAG if you have any questions about compatibility.
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:
: .
: . 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 .
: . 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 argument in Parameters).
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 .
test_ks_2sample
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) and 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 .
- 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