.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/statistics/bootstrap/plot_01_bootstrap_vs_parametric.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_api_gallery_statistics_bootstrap_plot_01_bootstrap_vs_parametric.py: Bootstrap vs. parametric confidence intervals ==================================================== Compares a bootstrap confidence interval for the median (which has no simple closed form) against the parametric t-based interval for the mean, on the same skewed dataset. .. GENERATED FROM PYTHON SOURCE LINES 11-15 .. code-block:: Python import numpy as np from mathematicskit.statistics import bootstrap_confidence_interval, mean_confidence_interval .. GENERATED FROM PYTHON SOURCE LINES 16-18 A skewed dataset where the mean and median tell different stories ------------------------------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 18-27 .. code-block:: Python rng = np.random.default_rng(0) data = rng.exponential(scale=5.0, size=300) mean_result = mean_confidence_interval(data, sigma=None) median_result = bootstrap_confidence_interval(data, statistic=np.median, n_resamples=5000, seed=0) print(f"mean: {mean_result.estimate:.3f}, 95% CI ({mean_result.lower:.3f}, {mean_result.upper:.3f})") print(f"median: {median_result.estimate:.3f}, 95% CI ({median_result.lower:.3f}, {median_result.upper:.3f})") .. rst-class:: sphx-glr-script-out .. code-block:: none mean: 5.793, 95% CI (5.153, 6.433) median: 4.006, 95% CI (3.505, 4.804) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.027 seconds) .. _sphx_glr_download_api_gallery_statistics_bootstrap_plot_01_bootstrap_vs_parametric.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_01_bootstrap_vs_parametric.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_01_bootstrap_vs_parametric.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_01_bootstrap_vs_parametric.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_