Compare samples using Smirnov testΒΆ

In this example we are going to estimate whether two samples follow the same distribution using the Smirnov test.

In [9]:
from __future__ import print_function
import openturns as ot
In [10]:
# Generate 3 samples, sample1 and sample2 according the same distribution
distribution1 = ot.Gumbel(5.5, 0.5)
distribution2 = ot.Uniform()

sample1 = distribution1.getSample(30)
sample2 = distribution1.getSample(30)
sample3 = distribution2.getSample(30)
In [11]:
# Test sample1 against sample2
test_result = ot.HypothesisTest.Smirnov(sample1, sample2)
print('Samples follow the same distribution?', test_result.getBinaryQualityMeasure(),
      'p-value=%.6g' % test_result.getPValue(),
      'threshold=%.6g' % test_result.getThreshold())
Samples follow the same distribution? True p-value=0.135004 threshold=0.05
In [12]:
# Test sample1 against sample3
test_result = ot.HypothesisTest.Smirnov(sample1, sample3)
print('Samples follow the same distribution?', test_result.getBinaryQualityMeasure(),
      'p-value=%.6g' % test_result.getPValue(),
      'threshold=%.6g' % test_result.getThreshold())
Samples follow the same distribution? False p-value=1.27501e-06 threshold=0.05