.. 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_distribution_fitting_plot_asymptotic_estimators_distribution.py:
Get the asymptotic distribution of the estimators
=================================================
In this example we introduce the `buildEstimator` method to obtain the asymptotic distribution of the parameters of a fitted distribution obtained from a `Factory`.
.. 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)
Set the random generator seed
.. code-block:: default
ot.RandomGenerator.SetSeed(0)
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.
.. code-block:: default
distribution = ot.Normal(0.0, 1.0)
sample = distribution.getSample(50)
estimated = ot.NormalFactory().build(sample)
We take a look at the estimated parameters :
.. code-block:: default
print(estimated.getParameter())
.. rst-class:: sphx-glr-script-out
Out:
.. code-block:: none
[0.0353171,0.968336]
The `buildEstimator` method gives the asymptotic parameters distribution.
.. code-block:: default
fittedRes = ot.NormalFactory().buildEstimator(sample)
paramDist = fittedRes.getParameterDistribution()
We draw the 2D-PDF of the parameters
.. code-block:: default
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:: /auto_data_analysis/distribution_fitting/images/sphx_glr_plot_asymptotic_estimators_distribution_001.png
:alt: Normal fitting : $(\mu, \sigma)$ iso-PDF
:class: sphx-glr-single-img
We draw the mean parameter :math:`\mu` distribution
.. code-block:: default
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:: /auto_data_analysis/distribution_fitting/images/sphx_glr_plot_asymptotic_estimators_distribution_002.png
:alt: Normal fitting : PDF of $\mu$
:class: sphx-glr-single-img
We draw the scale parameter :math:`\sigma` distribution
.. code-block:: default
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:: /auto_data_analysis/distribution_fitting/images/sphx_glr_plot_asymptotic_estimators_distribution_003.png
:alt: Normal fitting : PDF of $\sigma$
:class: sphx-glr-single-img
We observe on the two previous figures that the distribution is normal and centered around
the estimated value of the parameter.
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).
.. code-block:: default
distribution = ot.Pareto(1.0, 1.0, 0.0)
sample = distribution.getSample(50)
estimated = ot.ParetoFactory().build(sample)
We take a look at the estimated parameters :
.. code-block:: default
print(estimated.getParameter())
.. rst-class:: sphx-glr-script-out
Out:
.. code-block:: none
[0.393061,0.693541,0.696427]
The `buildEstimator` method gives the asymptotic parameters distribution.
.. code-block:: default
fittedRes = ot.ParetoFactory().buildEstimator(sample)
paramDist = fittedRes.getParameterDistribution()
We draw scale parameter :math:`\beta` distribution
.. code-block:: default
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:: /auto_data_analysis/distribution_fitting/images/sphx_glr_plot_asymptotic_estimators_distribution_004.png
:alt: Pareto fitting : PDF of $\beta$
:class: sphx-glr-single-img
We draw the shape parameter :math:`\alpha` distribution
.. code-block:: default
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:: /auto_data_analysis/distribution_fitting/images/sphx_glr_plot_asymptotic_estimators_distribution_005.png
:alt: Pareto fitting : PDF of $\alpha$
:class: sphx-glr-single-img
We draw the location parameter :math:`\gamma` distribution
.. code-block:: default
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:: /auto_data_analysis/distribution_fitting/images/sphx_glr_plot_asymptotic_estimators_distribution_006.png
:alt: Pareto fitting : PDF of $\gamma$
:class: sphx-glr-single-img
.. rst-class:: sphx-glr-timing
**Total running time of the script:** ( 0 minutes 0.782 seconds)
.. _sphx_glr_download_auto_data_analysis_distribution_fitting_plot_asymptotic_estimators_distribution.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_asymptotic_estimators_distribution.py `
.. container:: sphx-glr-download sphx-glr-download-jupyter
:download:`Download Jupyter notebook: plot_asymptotic_estimators_distribution.ipynb `
.. only:: html
.. rst-class:: sphx-glr-signature
`Gallery generated by Sphinx-Gallery `_