{
    "nbformat": 4,
    "nbformat_minor": 5,
    "metadata": {
        "kernelspec": {
            "display_name": "Python",
            "language": "python",
            "name": "python"
        },
        "language_info": {
            "name": "python"
        }
    },
    "cells": [
        {
            "id": "a9d832f1",
            "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": "0b95fbb1",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "import numpy as np\nfrom scipy.stats import hypergeom\nimport matplotlib.pyplot as plt",
            "outputs": []
        },
        {
            "id": "4323ce74",
            "cell_type": "markdown",
            "source": "Suppose we have a collection of 20 animals, of which 7 are dogs.  Then if\nwe want to know the probability of finding a given number of dogs if we\nchoose at random 12 of the 20 animals, we can initialize a frozen\ndistribution and plot the probability mass function:\n",
            "metadata": {}
        },
        {
            "id": "29b396f0",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "[M, n, N] = [20, 7, 12]\nrv = hypergeom(M, n, N)\nx = np.arange(0, n+1)\npmf_dogs = rv.pmf(x)",
            "outputs": []
        },
        {
            "id": "4af64518",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "fig = plt.figure()\nax = fig.add_subplot(111)\nax.plot(x, pmf_dogs, 'bo')\nax.vlines(x, 0, pmf_dogs, lw=2)\nax.set_xlabel('# of dogs in our group of chosen animals')\nax.set_ylabel('hypergeom PMF')\nplt.show()",
            "outputs": []
        },
        {
            "id": "47b29b3e",
            "cell_type": "markdown",
            "source": "Instead of using a frozen distribution we can also use `hypergeom`\nmethods directly.  To for example obtain the cumulative distribution\nfunction, use:\n",
            "metadata": {}
        },
        {
            "id": "f5f8062d",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "prb = hypergeom.cdf(x, M, n, N)",
            "outputs": []
        },
        {
            "id": "90c118d7",
            "cell_type": "markdown",
            "source": "And to generate random numbers:\n",
            "metadata": {}
        },
        {
            "id": "36cdbc82",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "R = hypergeom.rvs(M, n, N, size=10)",
            "outputs": []
        }
    ]
}