.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_data_analysis/statistical_tests/plot_test_normality.py" .. LINE NUMBERS ARE GIVEN BELOW. .. 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_tests_plot_test_normality.py: Test Normality ============== .. GENERATED FROM PYTHON SOURCE LINES 8-12 Normal fitting test using the Henry line ---------------------------------------- In this paragraph we perform a visual goodness-of-fit test for a univariate normal distribution using the Henry line test, which is the QQ plot adapted for Gaussian distributions. .. GENERATED FROM PYTHON SOURCE LINES 14-19 .. code-block:: default import openturns as ot import openturns.viewer as viewer from matplotlib import pylab as plt ot.Log.Show(ot.Log.NONE) .. GENERATED FROM PYTHON SOURCE LINES 20-21 We first create the data : .. GENERATED FROM PYTHON SOURCE LINES 21-24 .. code-block:: default distribution = ot.Normal(2.0, 0.5) sample1 = distribution.getSample(100) .. GENERATED FROM PYTHON SOURCE LINES 25-26 We draw the Henry line plot and expect a good fitting : .. GENERATED FROM PYTHON SOURCE LINES 26-29 .. code-block:: default graph = ot.VisualTest.DrawHenryLine(sample1) view = viewer.View(graph) .. image-sg:: /auto_data_analysis/statistical_tests/images/sphx_glr_plot_test_normality_001.png :alt: Henry plot :srcset: /auto_data_analysis/statistical_tests/images/sphx_glr_plot_test_normality_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 30-31 For comparison sake e draw the Henry line plot for a Beta distribution. The result is expected to be bad. .. GENERATED FROM PYTHON SOURCE LINES 31-36 .. code-block:: default sample2 = ot.Beta(0.7, 0.9, 0.0, 2.0).getSample(100) graph = ot.VisualTest.DrawHenryLine(sample2) view = viewer.View(graph) .. image-sg:: /auto_data_analysis/statistical_tests/images/sphx_glr_plot_test_normality_002.png :alt: Henry plot :srcset: /auto_data_analysis/statistical_tests/images/sphx_glr_plot_test_normality_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 37-45 Normality tests --------------- We use two tests to check whether a sample follows a normal distribution : - the Anderson-Darling test - the Cramer-Von Mises test .. GENERATED FROM PYTHON SOURCE LINES 47-49 We first generate two samples, one from a standard unit gaussian and another from a Gumbel distribution with parameters :math:`\beta = 1` and :math:`\gamma = 0`. .. GENERATED FROM PYTHON SOURCE LINES 49-52 .. code-block:: default sample1 = ot.Normal().getSample(200) sample2 = ot.Gumbel().getSample(200) .. GENERATED FROM PYTHON SOURCE LINES 53-56 We test the normality of the sample. We can display the result of the test as a yes/no answer with the `getBinaryQualityMeasure`. We can retrieve the p-value and the threshold with the `getPValue` and `getThreshold` methods. .. GENERATED FROM PYTHON SOURCE LINES 58-63 .. code-block:: default test_result = ot.NormalityTest.AndersonDarlingNormal(sample1) print('Component is normal?', test_result.getBinaryQualityMeasure(), 'p-value=%.6g' % test_result.getPValue(), 'threshold=%.6g' % test_result.getThreshold()) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none Component is normal? False p-value=0.021519 threshold=0.05 .. GENERATED FROM PYTHON SOURCE LINES 64-69 .. code-block:: default test_result = ot.NormalityTest.AndersonDarlingNormal(sample2) print('Component is normal?', test_result.getBinaryQualityMeasure(), 'p-value=%.6g' % test_result.getPValue(), 'threshold=%.6g' % test_result.getThreshold()) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none Component is normal? False p-value=1.45169e-10 threshold=0.05 .. GENERATED FROM PYTHON SOURCE LINES 70-75 .. code-block:: default test_result = ot.NormalityTest.CramerVonMisesNormal(sample1) print('Component is normal?', test_result.getBinaryQualityMeasure(), 'p-value=%.6g' % test_result.getPValue(), 'threshold=%.6g' % test_result.getThreshold()) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none Component is normal? False p-value=0.0438816 threshold=0.05 .. GENERATED FROM PYTHON SOURCE LINES 76-80 .. code-block:: default test_result = ot.NormalityTest.CramerVonMisesNormal(sample2) print('Component is normal?', test_result.getBinaryQualityMeasure(), 'p-value=%.6g' % test_result.getPValue(), 'threshold=%.6g' % test_result.getThreshold()) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none Component is normal? False p-value=4.33705e-08 threshold=0.05 .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.151 seconds) .. _sphx_glr_download_auto_data_analysis_statistical_tests_plot_test_normality.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_test_normality.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_test_normality.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_