Kolmogorov-Smirnov goodness-of-fit test - computation of p-value

Dear all,
does anybody know how Mathematica computes the p-value in the command KolmogorovSmirnovTest[data]. It is clear to me how the test statistic dn is computed but I tried to compute the p-value with the help of the so-called Kolmogorov distribution and also by using some modifications found in literature but I failed. What is also strange is the fact that the p-value given by Mathematica is far away from that computed with the Kolmogorov distribution also for large n.

Best,
Klaus

I wasn’t aware that RandomReal could work with a distribution but apparently it does. It would be more standard to use RandomVariate. In any event, preceding the generation of the random numbers with a call to SeedRandom (such as SeedRandom[12345]) will pretty much guarantee that everyone will get the same random numbers as you did.

When using the command with symbolic parameters for a normal distribution

KolmogorovSmirnovTest[data, NormalDistribution[\[Mu], \[Sigma]], "TestData"]

you are testing whether the data comes from a normal distribution. That is the Lilliefors Test and it has a different P-value calculation. See Lilliefors test - Wikipedia.

When you want to test against a specific distribution with specified parameters such as

KolmogorovSmirnovTest[data, NormalDistribution[0, 1], "TestData"]

then the formula for the P-value works.

Dear Jim,

thanks a lot for the answer!

Concerning the Kolmogorov-Smirnov-Test against s specific distribution with specified parameters:
In the literature, I found that instead of the Kolmogorov distribution FK(x) it is better to use the modification FK(x+1/(6*sqrt(n))+(x-1)/(4n)). With this modification I get approximately the same p-value as Mathematica but not exactly the same (see the attached notebook). Do you know, what Mathematica uses as CDF for computing the p-value?

Kolmogorov-Smirnov.nb (6.18 KB)