{
    "nbformat": 4,
    "nbformat_minor": 5,
    "metadata": {
        "kernelspec": {
            "display_name": "Python",
            "language": "python",
            "name": "python"
        },
        "language_info": {
            "name": "python"
        }
    },
    "cells": [
        {
            "id": "91dde5e5",
            "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": "ab14eaa5",
            "cell_type": "markdown",
            "source": "In epidemiology, individuals are classified as \"exposed\" or\n\"unexposed\" to some factor or treatment. If the occurrence of some\nillness is under study, those who have the illness are often\nclassified as \"cases\", and those without it are \"noncases\".  The\ncounts of the occurrences of these classes gives a contingency\ntable\n```\n\nexposed    unexposed\ncases          a           b\nnoncases       c           d\n\n```\nThe sample odds ratio may be written ``(a/c) / (b/d)``.  ``a/c`` can\nbe interpreted as the odds of a case occurring in the exposed group,\nand ``b/d`` as the odds of a case occurring in the unexposed group.\nThe sample odds ratio is the ratio of these odds.  If the odds ratio\nis greater than 1, it suggests that there is a positive association\nbetween being exposed and being a case.\n\nInterchanging the rows or columns of the contingency table inverts\nthe odds ratio, so it is important to understand the meaning of labels\ngiven to the rows and columns of the table when interpreting the\nodds ratio.\n\nConsider a hypothetical example where it is hypothesized that exposure to a\ncertain chemical is associated with increased occurrence of a certain\ndisease. Suppose we have the following table for a collection of 410 people\n```\n\nexposed unexposed\ncases        7       15\nnoncases    58      472\n\n```\nThe question we ask is \"Is exposure to the chemical associated with\nincreased risk of the disease?\"\n\nCompute the odds ratio:\n",
            "metadata": {}
        },
        {
            "id": "67b38dd3",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "from scipy.stats.contingency import odds_ratio\nres = odds_ratio([[7, 15], [58, 472]])\nres.statistic",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "3.7836687705553493"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "ab7c033c",
            "cell_type": "markdown",
            "source": "For this sample, the odds of getting the disease for those who have been\nexposed to the chemical are almost 3.8 times that of those who have not been\nexposed.\n\nWe can compute the 95% confidence interval for the odds ratio:\n",
            "metadata": {}
        },
        {
            "id": "a2c9e3a4",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "res.confidence_interval(confidence_level=0.95)",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "ConfidenceInterval(low=1.2514829132266785, high=10.363493716701269)"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "497a1eb7",
            "cell_type": "markdown",
            "source": "The 95% confidence interval for the conditional odds ratio is approximately\n(1.25, 10.4).\n\nFor a more detailed example, see :ref:`hypothesis_odds_ratio`.",
            "metadata": {}
        }
    ]
}