kolmogorovSmirnovTest

Performs a one-sample Kolmogorov-Smirnov test against a reference distribution.

The null hypothesis is that sample was drawn from distribution. The test computes the maximum absolute difference between the empirical cumulative distribution function (ECDF) of the sample and the theoretical CDF of the reference distribution. Uses Kolmogorov's asymptotic formula for the p-value approximation.

Example:

val sample = doubleArrayOf(-1.0, -0.5, 0.0, 0.5, 1.0, 1.5, -1.5, -0.3, 0.3, 0.8)
val result = kolmogorovSmirnovTest(sample, NormalDistribution.STANDARD)
result.statistic // D statistic (max ECDF-CDF deviation)
result.pValue // p-value
result.additionalInfo["dPlus"] // max(ECDF - CDF)
result.additionalInfo["dMinus"] // max(CDF - ECDF)

Return

a TestResult containing the D statistic, p-value, and additional info with "dPlus" and "dMinus".

Parameters

sample

the observed values. Must not be empty.

distribution

the reference continuous distribution to test against.


Performs a two-sample Kolmogorov-Smirnov test.

The null hypothesis is that sample1 and sample2 are drawn from the same distribution. The test computes the maximum absolute difference between the two empirical cumulative distribution functions. Uses Kolmogorov's asymptotic formula for the p-value approximation with an effective sample size derived from both sample sizes.

Example:

val s1 = doubleArrayOf(1.0, 2.0, 3.0, 4.0, 5.0)
val s2 = doubleArrayOf(6.0, 7.0, 8.0, 9.0, 10.0)
val result = kolmogorovSmirnovTest(s1, s2)
result.statistic // D statistic (max ECDF difference)
result.pValue // p-value

Return

a TestResult containing the D statistic and p-value.

Parameters

sample1

the first sample. Must not be empty.

sample2

the second sample. Must not be empty.