{
    "nbformat": 4,
    "nbformat_minor": 5,
    "metadata": {
        "kernelspec": {
            "display_name": "Python",
            "language": "python",
            "name": "python"
        },
        "language_info": {
            "name": "python"
        }
    },
    "cells": [
        {
            "id": "61158e38",
            "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": "159ea2f7",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "import numpy as np\nfrom scipy import stats\nimport matplotlib.pyplot as plt",
            "outputs": []
        },
        {
            "id": "4f9d9922",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "x = np.linspace(-5, 5, num=150)\ny = x + np.random.normal(size=x.size)\ny[11:15] += 10  # add outliers\ny[-5:] -= 7",
            "outputs": []
        },
        {
            "id": "50da8052",
            "cell_type": "markdown",
            "source": "Compute the slope, intercept and 90% confidence interval.  For comparison,\nalso compute the least-squares fit with `linregress`:\n",
            "metadata": {}
        },
        {
            "id": "fad7ef5c",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "res = stats.theilslopes(y, x, 0.90, method='separate')\nlsq_res = stats.linregress(x, y)",
            "outputs": []
        },
        {
            "id": "6cf58a10",
            "cell_type": "markdown",
            "source": "Plot the results. The Theil-Sen regression line is shown in red, with the\ndashed red lines illustrating the confidence interval of the slope (note\nthat the dashed red lines are not the confidence interval of the regression\nas the confidence interval of the intercept is not included). The green\nline shows the least-squares fit for comparison.\n",
            "metadata": {}
        },
        {
            "id": "6fcf146b",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "fig = plt.figure()\nax = fig.add_subplot(111)\nax.plot(x, y, 'b.')\nax.plot(x, res[1] + res[0] * x, 'r-')\nax.plot(x, res[1] + res[2] * x, 'r--')\nax.plot(x, res[1] + res[3] * x, 'r--')\nax.plot(x, lsq_res[1] + lsq_res[0] * x, 'g-')\nplt.show()",
            "outputs": []
        }
    ]
}