{
    "nbformat": 4,
    "nbformat_minor": 5,
    "metadata": {
        "kernelspec": {
            "display_name": "Python",
            "language": "python",
            "name": "python"
        },
        "language_info": {
            "name": "python"
        }
    },
    "cells": [
        {
            "id": "298e9771",
            "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": "f463d4b6",
            "cell_type": "markdown",
            "source": "Suppose we wish to test whether data generated by ``scipy.stats.norm.rvs``\nwere, in fact, drawn from the standard normal distribution. We choose a\nsignificance level of ``alpha=0.05``.\n",
            "metadata": {}
        },
        {
            "id": "f4e7c5ed",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "import numpy as np\nfrom scipy import stats\nrng = np.random.default_rng()\nx = stats.norm.rvs(size=500, random_state=rng)\nres = stats.cramervonmises(x, 'norm')\nres.statistic, res.pvalue",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "(0.1072085112565724, 0.5508482238203407)"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "22bea630",
            "cell_type": "markdown",
            "source": "The p-value exceeds our chosen significance level, so we do not\nreject the null hypothesis that the observed sample is drawn from the\nstandard normal distribution.\n\nNow suppose we wish to check whether the same samples shifted by 2.1 is\nconsistent with being drawn from a normal distribution with a mean of 2.\n",
            "metadata": {}
        },
        {
            "id": "b97b6082",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "y = x + 2.1\nres = stats.cramervonmises(y, 'norm', args=(2,))\nres.statistic, res.pvalue",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "(0.8364446265294695, 0.00596286797008283)"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "4af73498",
            "cell_type": "markdown",
            "source": "Here we have used the `args` keyword to specify the mean (``loc``)\nof the normal distribution to test the data against. This is equivalent\nto the following, in which we create a frozen normal distribution with\nmean 2.1, then pass its ``cdf`` method as an argument.\n",
            "metadata": {}
        },
        {
            "id": "9fe54b2b",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "frozen_dist = stats.norm(loc=2)\nres = stats.cramervonmises(y, frozen_dist.cdf)\nres.statistic, res.pvalue",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "(0.8364446265294695, 0.00596286797008283)"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "45f2b226",
            "cell_type": "markdown",
            "source": "In either case, we would reject the null hypothesis that the observed\nsample is drawn from a normal distribution with a mean of 2 (and default\nvariance of 1) because the p-value is less than our chosen\nsignificance level.",
            "metadata": {}
        }
    ]
}