# Test distribution fitting using Kolmogorov¶

In this example we are going to perform a Kolmogorov goodness-of-fit test for an 1-d continuous distribution.

[1]:

from __future__ import print_function
import openturns as ot


Create the data.

[2]:

distribution = ot.Normal()
sample = distribution.getSample(50)


## Case 1 : the distribution parameters are known.¶

In the case where the parameters of the distribution are known, the second parameter of the Kolmogorov static method is the distribution to be tested.

[3]:

result = ot.FittingTest.Kolmogorov(sample, distribution, 0.01)
print('Conclusion=', result.getBinaryQualityMeasure(), 'P-value=', result.getPValue())

Conclusion= True P-value= 0.6411393475140432


Test succeeded ?

[4]:

result.getBinaryQualityMeasure()

[4]:

True


P-Value associated to the risk

[5]:

result.getPValue()

[5]:

0.6411393475140432


Threshold associated to the test.

[6]:

result.getThreshold()

[6]:

0.01


Observed value of the statistic.

[7]:

result.getStatistic()

[7]:

0.10176815459988908


## Case 2 : the distribution parameters are estimated from the sample.¶

In the case where the parameters of the distribution are estimated from the sample, the second parameter of the Kolmogorov static method is the associated distribution factory to be tested.

[8]:

ot.ResourceMap.SetAsUnsignedInteger("FittingTest-KolmogorovSamplingSize",1000)

[9]:

distributionFactory = ot.NormalFactory()

[10]:

dist, result = ot.FittingTest.Kolmogorov(sample, distributionFactory, 0.01)
print('Conclusion=', result.getBinaryQualityMeasure(), 'P-value=', result.getPValue())

Conclusion= True P-value= 0.353

[11]:

dist

[11]:


Normal(mu = 0.0353171, sigma = 0.968336)

Test succeeded ?

[12]:

result.getBinaryQualityMeasure()

[12]:

True


P-Value associated to the risk

[13]:

result.getPValue()

[13]:

0.353


Threshold associated to the test.

[14]:

result.getThreshold()

[14]:

0.01


Observed value of the statistic.

[15]:

result.getStatistic()

[15]:

0.09091079601468799