The IMSL_KOLMOGOROV1 function performs a Kolmogorov-Smirnov one- sample test for continuous distributions.
This routine requires an IDL Advanced Math and Stats license. For more information, contact your sales or technical support representative.
The IMSL_KOLMOGOROV1 function performs a Kolmogorov-Smirnov goodness- of-fit test in one sample. The hypotheses tested follow:
- H0 : F (x) = F* (x) H1 :F (x) ≠ F* (x)
- H0 : F (x) ≥ F* (x) H1 : F (x) < F* (x)
- H0 : F (x) ≤ F* (x) H1 : F (x) > F* (x)
where F is the cumulative distribution function (CDF) of the random variable, and the theoretical CDF, F* , is specified via the supplied function f. Let n = N_ELEMENTS(x) − NMISSING. The test statistics for both one-sided alternatives:
and:
and the two-sided (Dn = DIFFERENCES(0)) alternative are computed as well as an asymptotic z-score (Result(0)) and p-values associated with the one-sided (Result(1)) and two-sided (Result(2)) hypotheses. For n > 80, asymptotic p-values are used (see Gibbons 1971). For n ≤ 80, exact one-sided p-values are computed according to a method given by Conover (1980, page 350). An approximate two-sided test p-value is obtained as twice the one-sided p-value. The approximation is very close for one- sided p-values less than 0.10 and becomes very bad as the one-sided p-values get larger.
Programming Notes
-
The theoretical CDF is assumed to be continuous. If the CDF is not continuous, the statistics:
will not be computed correctly.
- Estimation of parameters in the theoretical CDF from the sample data will tend to make the p-values associated with the test statistics too liberal. The empirical CDF will tend to be closer to the theoretical CDF than it should be.
- No attempt is made to check that all points in the sample are in the support of the theoretical CDF. If all sample points are not in the support of the CDF, the null hypothesis must be rejected.
Example
In this example, a random sample of size 100 is generated via routine IMSL_RANDOM for the uniform (0, 1) distribution. We want to test the null hypothesis that the CDF is the standard normal distribution with a mean of 0.5 and a variance equal to the uniform (0, 1) variance (1/12).
.RUN
FUNCTION l_Cdf, x
mean = 0.5
std = 0.2886751
z = (x - mean)/std
val = IMSL_NORMALCDF(z) RETURN, val
END
IMSL_RANDOMOPT, set = 123457
x = IMSL_RANDOM(100, /UNIFORM)
stats = IMSL_KOLMOGOROV1('l_cdf', x, DIFFERENCES = d, $
NMISSING = nm)
PRINT, 'D =', d(0)
PRINT, 'D+ =', d(1)
PRINT, 'D- =', d(2)
PRINT, 'Z =', stats(0)
PRINT, 'Prob greater D one sided =', stats(1)
D = 0.147083
D+ = 0.0809559
D- = 0.147083
Z = 1.47083
Prob greater D one sided = 0.0132111
Syntax
Result = IMSL_KOLMOGOROV1(F, X [, DIFFERENCES=variable] [, /DOUBLE] [, NMISSING=variable])
Return Value
One-dimensional array of length 3 containing Z, p1, and p2.
Arguments
F
A scalar string specifying a user-supplied function to compute the cumulative distribution function (CDF) at a given value. Argument F accepts the following parameter and returns the computed function value at this point:
- y: Point at which the function is to be evaluated.
- x: One-dimensional array containing the observations.
X
A one-dimensional array containing the observations.
Keywords
DIFFERENCES (optional)
Named variable into which a one-dimensional array containing Dn, Dn, Dn is stored.
DOUBLE (optional)
If present and nonzero, then double precision is used.
NMISSING (optional)
Named variable into which the number of missing values is stored.
Version History
See Also
IMSL_KOLMOGOROV2