Example

In this example, a random sample of size 100 is generated using class 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).

import com.imsl.stat.*;

public class KolmogorovOneSampleEx1 {

    static public void main(String arg[]) {
        CdfFunction cdf = new CdfFunction() {
            public double cdf(double x) {
                double mean = 0.5;
                double std = 0.2886751;
                double z = (x - mean) / std;
                return Cdf.normal(z);
            }
        };

        double x[] = new double[100];
        Random random = new Random(123457);
        random.setMultiplier(16807);
        for (int i = 0; i < x.length; i++) {
            x[i] = random.nextDouble();
        }

        KolmogorovOneSample kos = new KolmogorovOneSample(cdf, x);
        System.out.println("D  = " + kos.getTestStatistic());
        System.out.println("D+ = " + kos.getMaximumDifference());
        System.out.println("D- = " + kos.getMinimumDifference());
        System.out.println("Z   = " + kos.getZ());
        System.out.println("Prob greater D one sided = "
                + kos.getOneSidedPValue());
        System.out.println("Prob greater D two sided = "
                + kos.getTwoSidedPValue());
        System.out.println("N missing = " + kos.getNumberMissing());
    }
}

Output

D  = 0.12191406736055721
D+ = 0.12191406736055721
D- = 0.08694298500243408
Z   = 1.219140673605572
Prob greater D one sided = 0.05116968745900741
Prob greater D two sided = 0.10233937491801481
N missing = 0
Link to Java source.