{
    "nbformat": 4,
    "nbformat_minor": 5,
    "metadata": {
        "kernelspec": {
            "display_name": "Python",
            "language": "python",
            "name": "python"
        },
        "language_info": {
            "name": "python"
        }
    },
    "cells": [
        {
            "id": "f2e9f500",
            "cell_type": "markdown",
            "source": "<div class='alert alert-warning'>\n\nSciPy's interactive examples with Jupyterlite are experimental and may not always work as expected. Execution of cells containing imports may result in large downloads (up to 60MB of content for the first import from SciPy). Load times when importing from SciPy may take roughly 10-20 seconds. If you notice any problems, feel free to open an [issue](https://github.com/scipy/scipy/issues/new/choose).\n\n</div>",
            "metadata": {}
        },
        {
            "id": "c513c126",
            "cell_type": "markdown",
            "source": "First a basic example to demonstrate the outputs:\n",
            "metadata": {}
        },
        {
            "id": "617d354e",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "from scipy import stats\ndata = [6, 9, 12, 7, 8, 8, 13]\nmean, var, std = stats.bayes_mvs(data)\nmean",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "Mean(statistic=9.0, minmax=(7.103650222612533, 10.896349777387467))"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "b06daa2c",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "var",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "Variance(statistic=10.0, minmax=(3.176724206, 24.45910382))"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "12db4d8b",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "std",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "Std_dev(statistic=2.9724954732045084,\n        minmax=(1.7823367265645143, 4.945614605014631))"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "7fdbed04",
            "cell_type": "markdown",
            "source": "Now we generate some normally distributed random data, and get estimates of\nmean and standard deviation with 95% confidence intervals for those\nestimates:\n",
            "metadata": {}
        },
        {
            "id": "7a9154eb",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "n_samples = 100000\ndata = stats.norm.rvs(size=n_samples)\nres_mean, res_var, res_std = stats.bayes_mvs(data, alpha=0.95)",
            "outputs": []
        },
        {
            "id": "2653735f",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "import matplotlib.pyplot as plt\nfig = plt.figure()\nax = fig.add_subplot(111)\nax.hist(data, bins=100, density=True, label='Histogram of data')\nax.vlines(res_mean.statistic, 0, 0.5, colors='r', label='Estimated mean')\nax.axvspan(res_mean.minmax[0],res_mean.minmax[1], facecolor='r',\n           alpha=0.2, label=r'Estimated mean (95% limits)')\nax.vlines(res_std.statistic, 0, 0.5, colors='g', label='Estimated scale')\nax.axvspan(res_std.minmax[0],res_std.minmax[1], facecolor='g', alpha=0.2,\n           label=r'Estimated scale (95% limits)')",
            "outputs": []
        },
        {
            "id": "1144546b",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "ax.legend(fontsize=10)\nax.set_xlim([-4, 4])\nax.set_ylim([0, 0.5])\nplt.show()",
            "outputs": []
        }
    ]
}