hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_stat_prob_kolmogorov1 (g01ey)


    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example


nag_stat_prob_kolmogorov1 (g01ey) returns the upper tail probability associated with the one sample Kolmogorov–Smirnov distribution.


[result, ifail] = g01ey(n, d)
[result, ifail] = nag_stat_prob_kolmogorov1(n, d)


Let Snx be the sample cumulative distribution function and F0x the hypothesised theoretical distribution function.
nag_stat_prob_kolmogorov1 (g01ey) returns the upper tail probability, p, associated with the one-sided Kolmogorov–Smirnov test statistic Dn+ or Dn-, where these one-sided statistics are defined as follows;
Dn+ = supxSnx-F0x, Dn- = supxF0x-Snx.  
If n100 an exact method is used; for the details see Conover (1980). Otherwise a large sample approximation derived by Smirnov is used; see Feller (1948), Kendall and Stuart (1973) or Smirnov (1948).


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
Siegel S (1956) Non-parametric Statistics for the Behavioral Sciences McGraw–Hill
Smirnov N (1948) Table for estimating the goodness of fit of empirical distributions Ann. Math. Statist. 19 279–281


Compulsory Input Parameters

1:     n int64int32nag_int scalar
n, the number of observations in the sample.
Constraint: n1.
2:     d – double scalar
Contains the test statistic, Dn+ or Dn-.
Constraint: 0.0d1.0.

Optional Input Parameters


Output Parameters

1:     result – double scalar
The result of the function.
2:     ifail int64int32nag_int scalar
ifail=0 unless the function detects an error (see Error Indicators and Warnings).

Error Indicators and Warnings

Errors or warnings detected by the function:
On entry,n<1.
On entry,d<0.0,
An unexpected error has been triggered by this routine. Please contact NAG.
Your licence key may have expired or may not have been installed correctly.
Dynamic memory allocation failed.


The large sample distribution used as an approximation to the exact distribution should have a relative error of less than 2.5% for most cases.

Further Comments

The upper tail probability for the two-sided statistic, Dn=maxDn+,Dn-, can be approximated by twice the probability returned via nag_stat_prob_kolmogorov1 (g01ey), that is 2p. (Note that if the probability from nag_stat_prob_kolmogorov1 (g01ey) is greater than 0.5 then the two-sided probability should be truncated to 1.0). This approximation to the tail probability for Dn is good for small probabilities, (e.g., p0.10) but becomes very poor for larger probabilities.
The time taken by the function increases with n, until n>100. At this point the approximation is used and the time decreases significantly. The time then increases again modestly with n.


The following example reads in 10 different sample sizes and values for the test statistic Dn. The upper tail probability is computed and printed for each case.
function g01ey_example

fprintf('g01ey example results\n\n');

% Upper tail probabilities for 1-sample Kolmogorov–Smirnov distribution.
n = zeros(10,1,'int64');
n(1: 5) = 10;
n(6:10) = 400; 
d = [0.323; 0.369; 0.409; 0.457; 0.489; 0.0535; 0.061; 0.068; 0.076; 0.0815];

fprintf('     d       n    one-sided probability\n');
for j = 1:numel(d)

  [p, ifail] = g01ey( ...
                       n(j), d(j));

  fprintf('%8.4f%6d%17.4f\n', d(j), n(j), p);

g01ey example results

     d       n    one-sided probability
  0.3230    10           0.0994
  0.3690    10           0.0497
  0.4090    10           0.0251
  0.4570    10           0.0099
  0.4890    10           0.0050
  0.0535   400           0.1001
  0.0610   400           0.0502
  0.0680   400           0.0243
  0.0760   400           0.0096
  0.0815   400           0.0048

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015