.. 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 6-8 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 10-16 .. code-block:: Python 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 17-18 Set the random generator seed .. GENERATED FROM PYTHON SOURCE LINES 18-20 .. code-block:: Python ot.RandomGenerator.SetSeed(0) .. GENERATED FROM PYTHON SOURCE LINES 21-26 The standard normal ------------------- The parameters of the standard normal distribution are estimated by a method of moments method. Thus the asymptotic parameters distribution is normal and estimated by bootstrap on the initial data. .. GENERATED FROM PYTHON SOURCE LINES 26-30 .. code-block:: Python distribution = ot.Normal(0.0, 1.0) sample = distribution.getSample(50) estimated = ot.NormalFactory().build(sample) .. GENERATED FROM PYTHON SOURCE LINES 31-32 We take a look at the estimated parameters : .. GENERATED FROM PYTHON SOURCE LINES 32-34 .. code-block:: Python print(estimated.getParameter()) .. rst-class:: sphx-glr-script-out .. code-block:: none [0.0353171,0.968336] .. GENERATED FROM PYTHON SOURCE LINES 35-37 The `buildEstimator` method gives the asymptotic parameters distribution. .. GENERATED FROM PYTHON SOURCE LINES 37-40 .. code-block:: Python fittedRes = ot.NormalFactory().buildEstimator(sample) paramDist = fittedRes.getParameterDistribution() .. GENERATED FROM PYTHON SOURCE LINES 41-42 We draw the 2D-PDF of the parameters .. GENERATED FROM PYTHON SOURCE LINES 42-49 .. 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.png :alt: Normal fitting : $(\mu, \sigma)$ iso-PDF :srcset: /auto_data_analysis/distribution_fitting/images/sphx_glr_plot_asymptotic_estimators_distribution_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 50-51 We draw the mean parameter :math:`\mu` distribution .. GENERATED FROM PYTHON SOURCE LINES 51-57 .. 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.png :alt: Normal fitting : PDF of $\mu$ :srcset: /auto_data_analysis/distribution_fitting/images/sphx_glr_plot_asymptotic_estimators_distribution_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 58-59 We draw the scale parameter :math:`\sigma` distribution .. GENERATED FROM PYTHON SOURCE LINES 59-65 .. 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.png :alt: Normal fitting : PDF of $\sigma$ :srcset: /auto_data_analysis/distribution_fitting/images/sphx_glr_plot_asymptotic_estimators_distribution_003.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 66-68 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 71-79 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 `ParetoFactory` to fit the sample. In that case the asymptotic parameters distribution is estimated by bootstrap on the initial data and kernel fitting (see KernelSmoothing). .. GENERATED FROM PYTHON SOURCE LINES 81-85 .. 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 86-87 We take a look at the estimated parameters : .. GENERATED FROM PYTHON SOURCE LINES 87-89 .. 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 90-92 The `buildEstimator` method gives the asymptotic parameters distribution. .. GENERATED FROM PYTHON SOURCE LINES 92-95 .. code-block:: Python fittedRes = ot.ParetoFactory().buildEstimator(sample) paramDist = fittedRes.getParameterDistribution() .. GENERATED FROM PYTHON SOURCE LINES 96-97 We draw scale parameter :math:`\beta` distribution .. GENERATED FROM PYTHON SOURCE LINES 97-103 .. 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.png :alt: Pareto fitting : PDF of $\beta$ :srcset: /auto_data_analysis/distribution_fitting/images/sphx_glr_plot_asymptotic_estimators_distribution_004.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 104-105 We draw the shape parameter :math:`\alpha` distribution .. GENERATED FROM PYTHON SOURCE LINES 105-111 .. 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.png :alt: Pareto fitting : PDF of $\alpha$ :srcset: /auto_data_analysis/distribution_fitting/images/sphx_glr_plot_asymptotic_estimators_distribution_005.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 112-113 We draw the location parameter :math:`\gamma` distribution .. GENERATED FROM PYTHON SOURCE LINES 113-120 .. 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.png :alt: Pareto fitting : PDF of $\gamma$ :srcset: /auto_data_analysis/distribution_fitting/images/sphx_glr_plot_asymptotic_estimators_distribution_006.png :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 `