.. 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_chi2_fitting_test.py:
Distribution fitting test using Chi2
====================================
In this example we are going to perform a Chi2 goodness-of-fit test for an 1-d discrete distribution.
.. code-block:: default
from __future__ import print_function
import openturns as ot
import openturns.viewer as viewer
from matplotlib import pylab as plt
ot.Log.Show(ot.Log.NONE)
Create data
.. code-block:: default
distribution = ot.Poisson()
sample = distribution.getSample(30)
Fit a Poisson distribution
.. code-block:: default
distribution = ot.PoissonFactory().build(sample)
Test the fitted distribution
.. code-block:: default
result = ot.FittingTest.ChiSquared(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.7146093983625044
.. rst-class:: sphx-glr-timing
**Total running time of the script:** ( 0 minutes 0.002 seconds)
.. _sphx_glr_download_auto_data_analysis_statistical_hypothesis_testing_plot_chi2_fitting_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_chi2_fitting_test.py `
.. container:: sphx-glr-download sphx-glr-download-jupyter
:download:`Download Jupyter notebook: plot_chi2_fitting_test.ipynb `
.. only:: html
.. rst-class:: sphx-glr-signature
`Gallery generated by Sphinx-Gallery `_