{
  "__type": "IngestedDoc",
  "__tag": 4010,
  "_content": {
    "Notes": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The symbols used to denote the shape parameters ("
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "M",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "n",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", and "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "r",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ") are not universally accepted. See the Examples for a clarification of the definitions used here."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The probability mass function is defined as,"
            }
          ]
        },
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "f(k; M, n, r) = \\frac{{{k+r-1}\\choose{k}}{{M-r-k}\\choose{n-k}}}{{M \\choose n}}"
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "for "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "k \\in [0, n]"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "n \\in [0, M]"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "r \\in [0, M-n]"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", and the binomial coefficient is:"
            }
          ]
        },
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "\\binom{n}{k} \\equiv \\frac{n!}{k! (n - k)!}."
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "It is equivalent to observing "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "k"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " successes in "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "k+r-1"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " samples with "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "k+r"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "'th sample being a failure. The former can be modelled as a hypergeometric distribution. The probability of the latter is simply the number of failures remaining "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "M-n-(r-1)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " divided by the size of the remaining population "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "M-(k+r-1)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". This relationship can be shown as:"
            }
          ]
        },
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "NHG(k;M,n,r) = HG(k;M,n,k+r-1)\\frac{(M-n-(r-1))}{(M-(k+r-1))}"
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "where "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "NHG"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is probability mass function (PMF) of the negative hypergeometric distribution and "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "HG"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is the PMF of the hypergeometric distribution."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "%(after_notes)s"
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Warns": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Raises": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Yields": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Methods": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Returns": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "A negative hypergeometric discrete random variable."
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Receives": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Warnings": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Attributes": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Parameters": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Extended Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Consider a box containing "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "M"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " balls:, "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "n"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " red and "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "M-n"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " blue. We randomly sample balls from the box, one at a time and "
            },
            {
              "__type": "Emphasis",
              "__tag": 4047,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "without"
                }
              ]
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " replacement, until we have picked "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "r"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " blue balls. "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "nhypergeom",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is the distribution of the number of red balls "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "k"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " we have picked."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "%(before_notes)s"
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Other Parameters": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    }
  },
  "_ordered_sections": [
    "Summary",
    "Extended Summary",
    "Parameters",
    "Attributes",
    "Methods",
    "Returns",
    "Yields",
    "Receives",
    "Other Parameters",
    "Raises",
    "Warns",
    "Warnings",
    "Notes"
  ],
  "item_file": "/scipy/stats/_discrete_distns.py",
  "item_line": 738,
  "item_type": "class",
  "aliases": [
    "scipy.stats._discrete_distns.nhypergeom_gen"
  ],
  "example_section_data": {
    "__type": "Section",
    "__tag": 4015,
    "children": [
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "import numpy as np\nfrom scipy.stats import nhypergeom\nimport matplotlib.pyplot as plt\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nSuppose we have a collection of 20 animals, of which 7 are dogs.\nThen if we want to know the probability of finding a given number\nof dogs (successes) in a sample with exactly 12 animals that\naren't dogs (failures), we can initialize a frozen distribution\nand plot the probability mass function:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "M, n, r = [20, 7, 12]\nrv = nhypergeom(M, n, r)\nx = np.arange(0, n+2)\npmf_dogs = rv.pmf(x)\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "fig = plt.figure()\nax = fig.add_subplot(111)\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "ax.plot(x, pmf_dogs, 'bo')\nax.vlines(x, 0, pmf_dogs, lw=2)\nax.set_xlabel('# of dogs in our group with given 12 failures')\nax.set_ylabel('nhypergeom PMF')\n",
        "execution_status": "failure"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "plt.show()\n",
        "execution_status": "success"
      },
      {
        "__type": "Figure",
        "__tag": 4024,
        "value": {
          "__type": "RefInfo",
          "__tag": 4000,
          "module": "scipy",
          "version": "1.17.1",
          "kind": "assets",
          "path": "fig-7773d8764d43697e.png"
        }
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nInstead of using a frozen distribution we can also use `nhypergeom`\nmethods directly.  To for example obtain the probability mass\nfunction, use:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "prb = nhypergeom.pmf(x, M, n, r)\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nAnd to generate random numbers:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "R = nhypergeom.rvs(M, n, r, size=10)\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nTo verify the relationship between `hypergeom` and `nhypergeom`, use:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "from scipy.stats import hypergeom, nhypergeom\nM, n, r = 45, 13, 8\nk = 6\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "nhypergeom.pmf(k, M, n, r)\nhypergeom.pmf(k, M, n, k+r-1) * (M - n - (r-1)) / (M - (k+r-1))\n",
        "execution_status": "failure"
      }
    ],
    "title": [],
    "level": 0,
    "target": null
  },
  "see_also": [
    {
      "__type": "SeeAlsoItem",
      "__tag": 4028,
      "name": {
        "__type": "CrossRef",
        "__tag": 4002,
        "value": "binom",
        "reference": {
          "__type": "LocalRef",
          "__tag": 4022,
          "kind": "module",
          "path": "scipy.special.cython_special:binom"
        },
        "kind": "module"
      },
      "descriptions": [],
      "type": null
    },
    {
      "__type": "SeeAlsoItem",
      "__tag": 4028,
      "name": {
        "__type": "CrossRef",
        "__tag": 4002,
        "value": "hypergeom",
        "reference": {
          "__type": "RefInfo",
          "__tag": 4000,
          "module": "current-module",
          "version": "current-version",
          "kind": "to-resolve",
          "path": "hypergeom"
        },
        "kind": "module"
      },
      "descriptions": [],
      "type": null
    },
    {
      "__type": "SeeAlsoItem",
      "__tag": 4028,
      "name": {
        "__type": "CrossRef",
        "__tag": 4002,
        "value": "nbinom",
        "reference": {
          "__type": "RefInfo",
          "__tag": 4000,
          "module": "current-module",
          "version": "current-version",
          "kind": "to-resolve",
          "path": "nbinom"
        },
        "kind": "module"
      },
      "descriptions": [],
      "type": null
    }
  ],
  "signature": {
    "__type": "SignatureNode",
    "__tag": 4029,
    "kind": "function",
    "parameters": [
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "a",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "0"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "b",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "inf"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "name",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "None"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "badvalue",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "None"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "moment_tol",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "1e-08"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "values",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "None"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "inc",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "1"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "longname",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "None"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "shapes",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "None"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "seed",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "None"
      }
    ],
    "return_annotation": {
      "__type": "Empty",
      "__tag": 4031
    },
    "target_name": "nhypergeom_gen"
  },
  "references": [
    ".. [1] Negative Hypergeometric Distribution on Wikipedia",
    "       https://en.wikipedia.org/wiki/Negative_hypergeometric_distribution",
    "",
    ".. [2] Negative Hypergeometric Distribution from",
    "       http://www.math.wm.edu/~leemis/chart/UDR/PDFs/Negativehypergeometric.pdf"
  ],
  "qa": "scipy.stats._discrete_distns:nhypergeom_gen",
  "arbitrary": [],
  "local_refs": []
}