Click or drag to resize

Kolmogorov Smirnov Test

One sample Kolmogorov–Smirnov test of the null hypothesis that data in the sample is a random sample from specified distribution, against the alternative that the distribution is different.

This topic contains the following sections:

Kolmogorov-Smirnov Test Specification

The empirical distribution function Fn for n independent and identically distributed observations Xi is defined as

HT F

where HT Ix is the indicator function, equal to 1 if Xi ≤ x and equal to 0 otherwise.

The Kolmogorov–Smirnov statistic for a given cumulative distribution function F(x) is:

HT Kolm SmT

where supx is the supremum of the set of distances. If the sample comes from distribution F(x), then Dn converges to 0 almost surely. In practice, the statistic requires a relatively large number of data points to properly reject the null hypothesis.

The null hypothesis is rejected at level α if

HT Kolm Sm Formula

where Kα is found from

HT Kolm Sm Ka

K is the random variable which has Kolmogorov distribution.

Implementation

The following constructors create an instance of KolmogorovSmirnovTest class.

Constructor

Description

Performance

two-tailed test, default significance level

Constructor without parameters. Creates KolmogorovSmirnovTest instance with default significance level for two-tailed test.

methodKolmogorovSmirnovTest

default significance level

Creates KolmogorovSmirnovTest instance with default significance level and user defined tail.

methodKolmogorovSmirnovTest(Tail)

two-tailed test, user defined significance level

Creates KolmogorovSmirnovTest instance for two-tailed test and user-defined significance level.

methodKolmogorovSmirnovTest(Double)

user defined tail and significance level

Creates KolmogorovSmirnovTest instance with user defined significance level and tail.

methodKolmogorovSmirnovTest(Double, Tail)

The class provides the following methods:

Method

Description

Performance

update

Updates test statistic using provided sample and supposition about distribution.

Double array series:

methodUpdate(Double, CUDistribution)

Vector series:

methodUpdate(Vector, CUDistribution)

The class provides the following properties:

Property

Description

Performance

region of acceptance

We fail to reject null hypothesis if test statistics is between left and right borders of region of acceptance.

Region of acceptance left border:

PropertyAcceptanceRegionLeft

Region of acceptance right border:

PropertyAcceptanceRegionRight

p-value

The probability of obtaining a test statistic at least as extreme as the one that was actually observed, assuming that the null hypothesis is true.

PropertyPValue

Code Sample

The example of KolmogorovSmirnovTest class usage:

C#
 1using System;
 2using FinMath.LinearAlgebra;
 3using FinMath.Statistics.HypothesisTesting;
 4using FinMath.Statistics.Distributions;
 5
 6namespace FinMath.Samples
 7{
 8    class KolmogorovSmirnovTestSample
 9    {
10        static void Main()
11        {
12            //Create an instance of normal distribution.
13            Normal distr = new Normal(0, 1);
14
15            // Generate random series.
16            Vector series = Vector.Random(100);
17
18            // Create an instance of KolmogorovSmirnovTest.
19            KolmogorovSmirnovTest test = new KolmogorovSmirnovTest(0.05, Tail.Both);
20            test.Update(series, distr);
21
22            Console.WriteLine("Test Result:");
23            // Test decision
24            Console.WriteLine($"  The null hypothesis failed to be rejected: {test.Decision}");
25            // The statistic of KolmogorovSmirnovTest test.
26            Console.WriteLine($"  Statistics = {test.Statistics:0.000}");
27            // The p-value of the test statistic.
28            Console.WriteLine($"  P-Value = {test.PValue:0.000}");
29
30        }
31    }
32}

See Also