Test distribution fitting using Kolmogorov/Lilliefors¶

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

```from __future__ import print_function
import openturns as ot
ot.Log.Show(ot.Log.NONE)
```

Create the data.

```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, we must use the Kolmogorov static method and the distribution to be tested.

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

Out:

```Conclusion= True P-value= 0.9861140480396968
```

Test succeeded ?

```result.getBinaryQualityMeasure()
```

Out:

```True
```

P-Value associated to the risk

```result.getPValue()
```

Out:

```0.9861140480396968
```

Threshold associated to the test.

```result.getThreshold()
```

Out:

```0.01
```

Observed value of the statistic.

```result.getStatistic()
```

Out:

```0.06127263683768702
```

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

In the case where the parameters of the distribution are estimated from the sample, we must use the Lilliefors static method and the distribution factory to be tested.

```ot.ResourceMap.SetAsUnsignedInteger("FittingTest-LillieforsMaximumSamplingSize",1000)
```
```distributionFactory = ot.NormalFactory()
```
```dist, result = ot.FittingTest.Lilliefors(sample, distributionFactory, 0.01)
print('Conclusion=', result.getBinaryQualityMeasure(), 'P-value=', result.getPValue())
```

Out:

```Conclusion= True P-value= 0.983
```
```dist
```

Normal(mu = -0.0222592, sigma = 0.956433)

Test succeeded ?

```result.getBinaryQualityMeasure()
```

Out:

```True
```

P-Value associated to the risk

```result.getPValue()
```

Out:

```0.983
```

Threshold associated to the test.

```result.getThreshold()
```

Out:

```0.01
```

Observed value of the statistic.

```result.getStatistic()
```

Out:

```0.05110645729712043
```

Total running time of the script: ( 0 minutes 0.029 seconds)

Gallery generated by Sphinx-Gallery