{
    "nbformat": 4,
    "nbformat_minor": 5,
    "metadata": {
        "kernelspec": {
            "display_name": "Python",
            "language": "python",
            "name": "python"
        },
        "language_info": {
            "name": "python"
        }
    },
    "cells": [
        {
            "id": "38ddd944",
            "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": "1445e6be",
            "cell_type": "markdown",
            "source": "Generate perfectly correlated data, and observe that the xi correlation is\nnearly 1.0.\n",
            "metadata": {}
        },
        {
            "id": "57fc4940",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "import numpy as np\nfrom scipy import stats\nrng = np.random.default_rng()\nx = rng.uniform(0, 10, size=100)\ny = np.sin(x)\nres = stats.chatterjeexi(x, y)\nres.statistic",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "np.float64(0.9012901290129013)"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "40fe837e",
            "cell_type": "markdown",
            "source": "The probability of observing such a high value of the statistic under the\nnull hypothesis of independence is very low.\n",
            "metadata": {}
        },
        {
            "id": "1970465d",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "res.pvalue",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "np.float64(2.2206974648177804e-46)"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "82c10889",
            "cell_type": "markdown",
            "source": "As noise is introduced, the correlation coefficient decreases.\n",
            "metadata": {}
        },
        {
            "id": "93020762",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "noise = rng.normal(scale=[[0.1], [0.5], [1]], size=(3, 100))\nres = stats.chatterjeexi(x, y + noise, axis=-1)\nres.statistic",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([0.79507951, 0.41824182, 0.16651665])"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "1de0cfba",
            "cell_type": "markdown",
            "source": "Because the distribution of `y` is continuous, it is valid to pass\n``y_continuous=True``. The statistic is identical, and the p-value\n(not shown) is only slightly different.\n",
            "metadata": {}
        },
        {
            "id": "ae46533d",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "stats.chatterjeexi(x, y + noise, y_continuous=True, axis=-1).statistic",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([0.79507951, 0.41824182, 0.16651665])"
                    },
                    "execution_count": null
                }
            ]
        }
    ]
}