.. 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 :ref:`Go to the end ` 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-14 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 16-21 .. code-block:: Python import openturns as ot import openturns.viewer as viewer ot.Log.Show(ot.Log.NONE) .. GENERATED FROM PYTHON SOURCE LINES 22-23 We first create the data : .. GENERATED FROM PYTHON SOURCE LINES 23-26 .. code-block:: Python distribution = ot.Normal(2.0, 0.5) sample1 = distribution.getSample(100) .. GENERATED FROM PYTHON SOURCE LINES 27-28 We draw the Henry line plot and expect a good fitting : .. GENERATED FROM PYTHON SOURCE LINES 28-31 .. code-block:: Python 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 32-33 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 33-38 .. code-block:: Python 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 39-47 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 49-51 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 51-54 .. code-block:: Python sample1 = ot.Normal().getSample(200) sample2 = ot.Gumbel().getSample(200) .. GENERATED FROM PYTHON SOURCE LINES 55-58 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 60-68 .. code-block:: Python 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 .. code-block:: none Component is normal? True p-value=0.934998 threshold=0.05 .. GENERATED FROM PYTHON SOURCE LINES 69-77 .. code-block:: Python 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 .. code-block:: none Component is normal? False p-value=4.19717e-08 threshold=0.05 .. GENERATED FROM PYTHON SOURCE LINES 78-86 .. code-block:: Python 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 .. code-block:: none Component is normal? True p-value=0.949141 threshold=0.05 .. GENERATED FROM PYTHON SOURCE LINES 87-94 .. code-block:: Python 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 .. code-block:: none Component is normal? False p-value=1.15453e-06 threshold=0.05 .. _sphx_glr_download_auto_data_analysis_statistical_tests_plot_test_normality.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_test_normality.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_test_normality.py `