.. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_data_analysis_statistical_hypothesis_testing_plot_kolmogorov_test.py: 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. .. code-block:: default from __future__ import print_function import openturns as ot ot.Log.Show(ot.Log.NONE) Create the data. .. code-block:: default 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. .. code-block:: default result = ot.FittingTest.Kolmogorov(sample, distribution, 0.01) print('Conclusion=', result.getBinaryQualityMeasure(), 'P-value=', result.getPValue()) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none Conclusion= True P-value= 0.9861140480396968 Test succeeded ? .. code-block:: default result.getBinaryQualityMeasure() .. rst-class:: sphx-glr-script-out Out: .. code-block:: none True P-Value associated to the risk .. code-block:: default result.getPValue() .. rst-class:: sphx-glr-script-out Out: .. code-block:: none 0.9861140480396968 Threshold associated to the test. .. code-block:: default result.getThreshold() .. rst-class:: sphx-glr-script-out Out: .. code-block:: none 0.01 Observed value of the statistic. .. code-block:: default result.getStatistic() .. rst-class:: sphx-glr-script-out Out: .. code-block:: none 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. .. code-block:: default ot.ResourceMap.SetAsUnsignedInteger("FittingTest-LillieforsMaximumSamplingSize",1000) .. code-block:: default distributionFactory = ot.NormalFactory() .. code-block:: default dist, result = ot.FittingTest.Lilliefors(sample, distributionFactory, 0.01) print('Conclusion=', result.getBinaryQualityMeasure(), 'P-value=', result.getPValue()) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none Conclusion= True P-value= 0.983 .. code-block:: default dist .. raw:: html

Normal(mu = -0.0222592, sigma = 0.956433)



Test succeeded ? .. code-block:: default result.getBinaryQualityMeasure() .. rst-class:: sphx-glr-script-out Out: .. code-block:: none True P-Value associated to the risk .. code-block:: default result.getPValue() .. rst-class:: sphx-glr-script-out Out: .. code-block:: none 0.983 Threshold associated to the test. .. code-block:: default result.getThreshold() .. rst-class:: sphx-glr-script-out Out: .. code-block:: none 0.01 Observed value of the statistic. .. code-block:: default result.getStatistic() .. rst-class:: sphx-glr-script-out Out: .. code-block:: none 0.05110645729712043 .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.029 seconds) .. _sphx_glr_download_auto_data_analysis_statistical_hypothesis_testing_plot_kolmogorov_test.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_kolmogorov_test.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_kolmogorov_test.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_