.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_data_analysis/distribution_fitting/plot_asymptotic_estimators_distribution.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_distribution_fitting_plot_asymptotic_estimators_distribution.py: Get the asymptotic distribution of the estimators ================================================= .. GENERATED FROM PYTHON SOURCE LINES 7-9 In this example we introduce the `buildEstimator` method to obtain the asymptotic distribution of the parameters of a fitted distribution obtained from a `Factory`. .. GENERATED FROM PYTHON SOURCE LINES 11-16 .. code-block:: Python import openturns as ot import openturns.viewer as viewer from matplotlib import pyplot as plt .. GENERATED FROM PYTHON SOURCE LINES 17-22 The standard Normal ------------------- The parameters of the standard Normal distribution are estimated by a method of moments. Thus the asymptotic parameters distribution is Normal and estimated by bootstrap on the initial data. .. GENERATED FROM PYTHON SOURCE LINES 22-26 .. code-block:: Python distribution = ot.Normal(0.0, 1.0) sample = distribution.getSample(50) estimated = ot.NormalFactory().build(sample) .. GENERATED FROM PYTHON SOURCE LINES 27-28 We take a look at the estimated parameters : .. GENERATED FROM PYTHON SOURCE LINES 28-30 .. code-block:: Python print(estimated.getParameter()) .. rst-class:: sphx-glr-script-out .. code-block:: none [0.0353171,0.968336] .. GENERATED FROM PYTHON SOURCE LINES 31-33 The `buildEstimator` method gives the asymptotic parameters distribution. .. GENERATED FROM PYTHON SOURCE LINES 33-36 .. code-block:: Python fittedRes = ot.NormalFactory().buildEstimator(sample) paramDist = fittedRes.getParameterDistribution() .. GENERATED FROM PYTHON SOURCE LINES 37-38 We draw the 2d-PDF of the parameters .. GENERATED FROM PYTHON SOURCE LINES 38-45 .. code-block:: Python graph = paramDist.drawPDF() graph.setXTitle(r"$\mu$") graph.setYTitle(r"$\sigma$") graph.setTitle(r"Normal fitting : $(\mu, \sigma)$ iso-PDF") view = viewer.View(graph) .. image-sg:: /auto_data_analysis/distribution_fitting/images/sphx_glr_plot_asymptotic_estimators_distribution_001.svg :alt: Normal fitting : $(\mu, \sigma)$ iso-PDF :srcset: /auto_data_analysis/distribution_fitting/images/sphx_glr_plot_asymptotic_estimators_distribution_001.svg :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 46-47 We draw the mean parameter :math:`\mu` distribution .. GENERATED FROM PYTHON SOURCE LINES 47-53 .. code-block:: Python graph = paramDist.getMarginal(0).drawPDF() graph.setTitle(r"Normal fitting : PDF of $\mu$") graph.setXTitle(r"$\mu$") graph.setLegends(["PDF"]) view = viewer.View(graph) .. image-sg:: /auto_data_analysis/distribution_fitting/images/sphx_glr_plot_asymptotic_estimators_distribution_002.svg :alt: Normal fitting : PDF of $\mu$ :srcset: /auto_data_analysis/distribution_fitting/images/sphx_glr_plot_asymptotic_estimators_distribution_002.svg :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 54-55 We draw the scale parameter :math:`\sigma` distribution .. GENERATED FROM PYTHON SOURCE LINES 55-61 .. code-block:: Python graph = paramDist.getMarginal(1).drawPDF() graph.setTitle(r"Normal fitting : PDF of $\sigma$") graph.setXTitle(r"$\sigma$") graph.setLegends(["PDF"]) view = viewer.View(graph) .. image-sg:: /auto_data_analysis/distribution_fitting/images/sphx_glr_plot_asymptotic_estimators_distribution_003.svg :alt: Normal fitting : PDF of $\sigma$ :srcset: /auto_data_analysis/distribution_fitting/images/sphx_glr_plot_asymptotic_estimators_distribution_003.svg :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 62-64 We observe on the two previous figures that the distribution is Normal and centered around the estimated value of the parameter. .. GENERATED FROM PYTHON SOURCE LINES 67-75 The Pareto distribution ----------------------- We consider a Pareto distribution with a scale parameter :math:`\beta=1.0`, a shape parameter :math:`\alpha=1.0` and a location parameter :math:`\gamma = 0.0`. We generate a sample from this distribution and use a :class:`~openturns.ParetoFactory` to fit the sample. In that case the asymptotic parameters distribution is estimated by bootstrap on the initial data and kernel fitting (see :class:`~openturns.KernelSmoothing`). .. GENERATED FROM PYTHON SOURCE LINES 77-81 .. code-block:: Python distribution = ot.Pareto(1.0, 1.0, 0.0) sample = distribution.getSample(50) estimated = ot.ParetoFactory().build(sample) .. GENERATED FROM PYTHON SOURCE LINES 82-83 We take a look at the estimated parameters : .. GENERATED FROM PYTHON SOURCE LINES 83-85 .. code-block:: Python print(estimated.getParameter()) .. rst-class:: sphx-glr-script-out .. code-block:: none [0.39768,0.696349,0.690277] .. GENERATED FROM PYTHON SOURCE LINES 86-88 The `buildEstimator` method gives the asymptotic parameters distribution. .. GENERATED FROM PYTHON SOURCE LINES 88-91 .. code-block:: Python fittedRes = ot.ParetoFactory().buildEstimator(sample) paramDist = fittedRes.getParameterDistribution() .. GENERATED FROM PYTHON SOURCE LINES 92-93 We draw scale parameter :math:`\beta` distribution .. GENERATED FROM PYTHON SOURCE LINES 93-99 .. code-block:: Python graph = paramDist.getMarginal(0).drawPDF() graph.setTitle(r"Pareto fitting : PDF of $\beta$") graph.setXTitle(r"$\beta$") graph.setLegends(["PDF"]) view = viewer.View(graph) .. image-sg:: /auto_data_analysis/distribution_fitting/images/sphx_glr_plot_asymptotic_estimators_distribution_004.svg :alt: Pareto fitting : PDF of $\beta$ :srcset: /auto_data_analysis/distribution_fitting/images/sphx_glr_plot_asymptotic_estimators_distribution_004.svg :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 100-101 We draw the shape parameter :math:`\alpha` distribution .. GENERATED FROM PYTHON SOURCE LINES 101-107 .. code-block:: Python graph = paramDist.getMarginal(1).drawPDF() graph.setTitle(r"Pareto fitting : PDF of $\alpha$") graph.setXTitle(r"$\alpha$") graph.setLegends(["PDF"]) view = viewer.View(graph) .. image-sg:: /auto_data_analysis/distribution_fitting/images/sphx_glr_plot_asymptotic_estimators_distribution_005.svg :alt: Pareto fitting : PDF of $\alpha$ :srcset: /auto_data_analysis/distribution_fitting/images/sphx_glr_plot_asymptotic_estimators_distribution_005.svg :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 108-109 We draw the location parameter :math:`\gamma` distribution .. GENERATED FROM PYTHON SOURCE LINES 109-116 .. code-block:: Python graph = paramDist.getMarginal(2).drawPDF() graph.setTitle(r"Pareto fitting : PDF of $\gamma$") graph.setXTitle(r"$\gamma$") graph.setLegends(["PDF"]) view = viewer.View(graph) plt.show() .. image-sg:: /auto_data_analysis/distribution_fitting/images/sphx_glr_plot_asymptotic_estimators_distribution_006.svg :alt: Pareto fitting : PDF of $\gamma$ :srcset: /auto_data_analysis/distribution_fitting/images/sphx_glr_plot_asymptotic_estimators_distribution_006.svg :class: sphx-glr-single-img .. _sphx_glr_download_auto_data_analysis_distribution_fitting_plot_asymptotic_estimators_distribution.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_asymptotic_estimators_distribution.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_asymptotic_estimators_distribution.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_asymptotic_estimators_distribution.zip `