Results from the Kolmogorov-Smirnov test

[email protected] Fri, 25 Feb 2022 08:00:29 -0000
Newsgroups gmane.comp.python.scientific.user
Message-ID <[email protected]>
I am having problems in interpreting the results from the Kolmogorov Smrinov test function ks_2samp.

The results I get from this function are not in agreement with the other implementations of this test I am using (ROOT, wikipedia formulas, several on-line calculators).

As an example, I am using the following data samples:

s1 = [7,4,2,4]
s2 = [3,5,7,9,28,35,40,22,33,55]

From ks_2samp I get:

print(ks_2samp(s1,s2))
Ks_2sampResult(statistic=0.69999999999999996, pvalue=0.063697238353882635)

While the KolmogorovSmirnov2SamplesTest from ROOT returns:

  Int_t n1 = 4;
  Double_t sample1[] = {7.,4.,2.,4.};
  Int_t n2 = 10;
  Double_t sample2[] = {3.,5.,7.,9.,28.,35.,40.,22.,33.,55.};
  ROOT::Math::GoFTest* goftest_2 = new ROOT::Math::GoFTest(n1, sample1, n2, sample2);
  Double_t Dn_1 = goftest_2->KolmogorovSmirnov2SamplesTest("t");
  Double_t pvalueKS_1 = goftest_2-> KolmogorovSmirnov2SamplesTest();
  printf("Dn = %6.4f p = %6.4f\n",Dn_1,pvalueKS_1);

Dn = 0.7000 p = 0.1216

I obtained the same result by using the algorithm described in the Kolmogorov Smirnov test page on Wikipedia (https://en.wikipedia.org/wiki/Kolmogorov%E2%80%93Smirnov_test).

Also the same result is obtained from several on-line calculators for this test, e.g.

https://www.aatbio.com/tools/kolmogorov-smirnov-k-s-test-calculator
https://scistatcalc.blogspot.com/2013/11/kolmogorov-smirnov-test-calculator.html

I noticed that the discrepancy tends to become smaller if the data samples sizes grow.

Am I doing something wrong or there is an explanation for this discrepnacy?

For completeness, I am using python3-3.6.8-18 and python36-scipy-0.18.1-2.

Thank you

Emanuele Leonardi
_______________________________________________
SciPy-User mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/scipy-user.python.org/
Member address: [email protected]