{
    "nbformat": 4,
    "nbformat_minor": 5,
    "metadata": {
        "kernelspec": {
            "display_name": "Python",
            "language": "python",
            "name": "python"
        },
        "language_info": {
            "name": "python"
        }
    },
    "cells": [
        {
            "id": "e8952a39",
            "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": "0fd43f6b",
            "cell_type": "markdown",
            "source": "To evaluate the probability mass function of the multivariate\nhypergeometric distribution, with a dichotomous population of size\n$10$ and $20$, at a sample of size $12$ with\n$8$ objects of the first type and $4$ objects of the\nsecond type, use:\n",
            "metadata": {}
        },
        {
            "id": "7947b40a",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "from scipy.stats import multivariate_hypergeom\nmultivariate_hypergeom.pmf(x=[8, 4], m=[10, 20], n=12)",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "0.0025207176631464523"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "04a54441",
            "cell_type": "markdown",
            "source": "The `multivariate_hypergeom` distribution is identical to the\ncorresponding `hypergeom` distribution (tiny numerical differences\nnotwithstanding) when only two types (good and bad) of objects\nare present in the population as in the example above. Consider\nanother example for a comparison with the hypergeometric distribution:\n",
            "metadata": {}
        },
        {
            "id": "71929bd1",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "from scipy.stats import hypergeom\nmultivariate_hypergeom.pmf(x=[3, 1], m=[10, 5], n=4)",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "0.4395604395604395"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "dab56e96",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "hypergeom.pmf(k=3, M=15, n=4, N=10)",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "0.43956043956044005"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "1609b79b",
            "cell_type": "markdown",
            "source": "The functions ``pmf``, ``logpmf``, ``mean``, ``var``, ``cov``, and ``rvs``\nsupport broadcasting, under the convention that the vector parameters\n(``x``, ``m``, and ``n``) are interpreted as if each row along the last\naxis is a single object. For instance, we can combine the previous two\ncalls to `multivariate_hypergeom` as\n",
            "metadata": {}
        },
        {
            "id": "f4b79062",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "multivariate_hypergeom.pmf(x=[[8, 4], [3, 1]], m=[[10, 20], [10, 5]],\n                           n=[12, 4])",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([0.00252072, 0.43956044])"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "fe929f2a",
            "cell_type": "markdown",
            "source": "This broadcasting also works for ``cov``, where the output objects are\nsquare matrices of size ``m.shape[-1]``. For example:\n",
            "metadata": {}
        },
        {
            "id": "b0a695d2",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "multivariate_hypergeom.cov(m=[[7, 9], [10, 15]], n=[8, 12])",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([[[ 1.05, -1.05],\n        [-1.05,  1.05]],\n       [[ 1.56, -1.56],\n        [-1.56,  1.56]]])"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "35027ca3",
            "cell_type": "markdown",
            "source": "That is, ``result[0]`` is equal to\n``multivariate_hypergeom.cov(m=[7, 9], n=8)`` and ``result[1]`` is equal\nto ``multivariate_hypergeom.cov(m=[10, 15], n=12)``.\n\nAlternatively, the object may be called (as a function) to fix the `m`\nand `n` parameters, returning a \"frozen\" multivariate hypergeometric\nrandom variable.\n",
            "metadata": {}
        },
        {
            "id": "c1d09a96",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "rv = multivariate_hypergeom(m=[10, 20], n=12)\nrv.pmf(x=[8, 4])",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "0.0025207176631464523"
                    },
                    "execution_count": null
                }
            ]
        }
    ]
}