{
    "nbformat": 4,
    "nbformat_minor": 5,
    "metadata": {
        "kernelspec": {
            "display_name": "Python",
            "language": "python",
            "name": "python"
        },
        "language_info": {
            "name": "python"
        }
    },
    "cells": [
        {
            "id": "704d3481",
            "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": "9740d8ea",
            "cell_type": "markdown",
            "source": "We follow the example of table 3 in [1]: Fourteen children were divided\nrandomly into two groups. Their ranks at performing a specific tests are\nas follows.\n",
            "metadata": {}
        },
        {
            "id": "781a8f5b",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "import numpy as np\nx = [1, 2, 3, 4, 6, 7, 8]\ny = [5, 9, 10, 11, 12, 13, 14]",
            "outputs": []
        },
        {
            "id": "5ba8d9f6",
            "cell_type": "markdown",
            "source": "We use the BWS test to assess whether there is a statistically significant\ndifference between the two groups.\nThe null hypothesis is that there is no difference in the distributions of\nperformance between the two groups. We decide that a significance level of\n1% is required to reject the null hypothesis in favor of the alternative\nthat the distributions are different.\nSince the number of samples is very small, we can compare the observed test\nstatistic against the *exact* distribution of the test statistic under the\nnull hypothesis.\n",
            "metadata": {}
        },
        {
            "id": "b8f4c172",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "from scipy.stats import bws_test\nres = bws_test(x, y)\nprint(res.statistic)",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "5.132167152575315"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "07498bc8",
            "cell_type": "markdown",
            "source": "This agrees with $B = 5.132$ reported in [1]. The *p*-value produced\nby `bws_test` also agrees with $p = 0.0029$ reported in [1].\n",
            "metadata": {}
        },
        {
            "id": "6451bb66",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "print(res.pvalue)",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "0.002913752913752914"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "d4380680",
            "cell_type": "markdown",
            "source": "Because the p-value is below our threshold of 1%, we take this as evidence\nagainst the null hypothesis in favor of the alternative that there is a\ndifference in performance between the two groups.",
            "metadata": {}
        }
    ]
}