{
  "__type": "IngestedDoc",
  "__tag": 4010,
  "_content": {},
  "_ordered_sections": [],
  "item_file": null,
  "item_line": null,
  "item_type": null,
  "aliases": [],
  "example_section_data": {
    "__type": "Section",
    "__tag": 4015,
    "children": [],
    "title": [],
    "level": 0,
    "target": null
  },
  "see_also": [],
  "signature": null,
  "references": null,
  "qa": "tutorial:stats:probability_distributions",
  "arbitrary": [
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Emphasis",
              "__tag": 4047,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "SciPy has two infrastructures for working with probability distributions.\nThis tutorial is for the older one, which has many pre-defined distributions;\nhowever, the new infrastructure can be used with most of these and has many\nadvantages. For the new infrastructure, see"
                }
              ]
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "rv_infrastructure",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "docs",
                "path": "rv_infrastructure"
              },
              "kind": "docs"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "There are two general distribution classes that have been implemented for encapsulating "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "continuous random variables",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "docs",
                "path": "tutorial:stats:continuous"
              },
              "kind": "exists"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "discrete random variables",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "docs",
                "path": "tutorial:stats:discrete"
              },
              "kind": "exists"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". Over 100 continuous random variables (RVs) and 20 discrete random variables have been implemented using these classes. For mathematical reference information about individual distributions, please see "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "continuous",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "docs",
                "path": "continuous"
              },
              "kind": "docs"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "discrete",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "docs",
                "path": "discrete"
              },
              "kind": "docs"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "All of the statistics functions are located in the sub-package "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "scipy.stats",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "scipy",
                "version": "*",
                "kind": "api",
                "path": "scipy.stats"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and a fairly complete listing of these functions and random variables available can also be obtained from the docstring for the stats sub-package."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "In the discussion below, we mostly focus on continuous RVs. Nearly everything also applies to discrete variables, but we point out some differences here: "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "discrete_points_label",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "docs",
                "path": "tutorial:stats:probability_distributions"
              },
              "kind": "exists"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "In the code samples below, we assume that the "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "scipy.stats",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "scipy",
                "version": "*",
                "kind": "api",
                "path": "scipy.stats"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " package is imported as"
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> from scipy import stats",
              "execution_status": null
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "and in some cases we assume that individual objects are imported as"
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> from scipy.stats import norm",
              "execution_status": null
            }
          ]
        },
        {
          "__type": "BulletList",
          "__tag": 4053,
          "ordered": false,
          "start": 1,
          "children": [
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "Continuous Statistical Distributions",
                      "reference": {
                        "__type": "LocalRef",
                        "__tag": 4022,
                        "kind": "docs",
                        "path": "tutorial:stats:continuous"
                      },
                      "kind": "exists"
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "Discrete Statistical Distributions",
                      "reference": {
                        "__type": "LocalRef",
                        "__tag": 4022,
                        "kind": "docs",
                        "path": "tutorial:stats:discrete"
                      },
                      "kind": "exists"
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Probability distributions"
        }
      ],
      "level": 0,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "First of all, all distributions are accompanied with help functions. To obtain just some basic information, we print the relevant docstring: "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "print(stats.norm.__doc__)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "To find the support, i.e., upper and lower bounds of the distribution, call:"
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> print('bounds of distribution lower: %s, upper: %s' % norm.support())\nbounds of distribution lower: -inf, upper: inf",
              "execution_status": null
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "We can list all methods and properties of the distribution with "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "dir(norm)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". As it turns out, some of the methods are private, although they are not named as such (their names do not start with a leading underscore), for example "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "veccdf"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", are only available for internal calculation (those methods will give warnings when one tries to use them, and will be removed at some point)."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "To obtain the "
            },
            {
              "__type": "Emphasis",
              "__tag": 4047,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "real"
                }
              ]
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " main methods, we list the methods of the frozen distribution. (We explain the meaning of a "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "frozen",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " distribution below)."
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> rv = norm()\n>>> dir(rv)  # reformatted\n['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__',\n '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__',\n '__init__', '__le__', '__lt__', '__module__', '__ne__', '__new__',\n '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__',\n '__str__', '__subclasshook__', '__weakref__', 'a', 'args', 'b', 'cdf',\n 'dist', 'entropy', 'expect', 'interval', 'isf', 'kwds', 'logcdf',\n 'logpdf', 'logpmf', 'logsf', 'mean', 'median', 'moment', 'pdf', 'pmf',\n 'ppf', 'random_state', 'rvs', 'sf', 'stats', 'std', 'var']",
              "execution_status": null
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Finally, we can obtain the list of available distribution through introspection:"
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> dist_continu = [d for d in dir(stats) if\n...                 isinstance(getattr(stats, d), stats.rv_continuous)]\n>>> dist_discrete = [d for d in dir(stats) if\n...                  isinstance(getattr(stats, d), stats.rv_discrete)]\n>>> print('number of continuous distributions: %d' % len(dist_continu))\nnumber of continuous distributions: 109\n>>> print('number of discrete distributions:   %d' % len(dist_discrete))\nnumber of discrete distributions:   21",
              "execution_status": null
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Getting help"
        }
      ],
      "level": 1,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The main public methods for continuous  RVs are:"
            }
          ]
        },
        {
          "__type": "BulletList",
          "__tag": 4053,
          "ordered": false,
          "start": 1,
          "children": [
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "rvs:   Random Variates"
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "pdf:   Probability Density Function"
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "cdf:   Cumulative Distribution Function"
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "sf:    Survival Function (1-CDF)"
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "ppf:   Percent Point Function (Inverse of CDF)"
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "isf:   Inverse Survival Function (Inverse of SF)"
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "stats: Return mean, variance, (Fisher's) skew, or (Fisher's) kurtosis"
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "moment: non-central moments of the distribution"
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Let's take a normal RV as an example."
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> norm.cdf(0)\n0.5",
              "execution_status": null
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "To compute the "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "cdf"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " at a number of points, we can pass a list or a numpy array."
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> norm.cdf([-1., 0, 1])\narray([ 0.15865525,  0.5,  0.84134475])\n>>> import numpy as np\n>>> norm.cdf(np.array([-1., 0, 1]))\narray([ 0.15865525,  0.5,  0.84134475])",
              "execution_status": null
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Thus, the basic methods, such as "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "pdf",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "cdf",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", and so on, are vectorized."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Other generally useful methods are supported too:"
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> norm.mean(), norm.std(), norm.var()\n(0.0, 1.0, 1.0)\n>>> norm.stats(moments=\"mv\")\n(array(0.0), array(1.0))",
              "execution_status": null
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "To find the median of a distribution, we can use the percent point function "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "ppf"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", which is the inverse of the "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "cdf"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ":"
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> norm.ppf(0.5)\n0.0",
              "execution_status": null
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "To generate a sequence of random variates, use the "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "size"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " keyword argument:"
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> norm.rvs(size=3)\narray([-0.35687759,  1.34347647, -0.11710531])   # random",
              "execution_status": null
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Don't think that "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "norm.rvs(5)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " generates 5 variates:"
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> norm.rvs(5)\n5.471435163732493  # random",
              "execution_status": null
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Here, "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "5"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " with no keyword is being interpreted as the first possible keyword argument, "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "loc"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", which is the first of a pair of keyword arguments taken by all continuous distributions. This brings us to the topic of the next subsection."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Common methods"
        }
      ],
      "level": 1,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Drawing random numbers relies on generators from "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "numpy.random",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "numpy",
                "version": "*",
                "kind": "api",
                "path": "numpy.random"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " package. In the examples above, the specific stream of random numbers is not reproducible across runs. To achieve reproducibility, you can explicitly "
            },
            {
              "__type": "Emphasis",
              "__tag": 4047,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "seed"
                }
              ]
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " a random number generator. In NumPy, a generator is an instance of "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "numpy.random.Generator",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "numpy",
                "version": "*",
                "kind": "api",
                "path": "numpy.random._generator:Generator"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". Here is the canonical way to create a generator:"
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> from numpy.random import default_rng\n>>> rng = default_rng()",
              "execution_status": null
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "And fixing the seed can be done like this:"
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> # do NOT copy this value\n>>> rng = default_rng(301439351238479871608357552876690613766)",
              "execution_status": null
            }
          ]
        },
        {
          "__type": "Admonition",
          "__tag": 4056,
          "kind": "warning",
          "base_type": "warning",
          "children": [
            {
              "__type": "AdmonitionTitle",
              "__tag": 4055,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "warning "
                }
              ]
            },
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "Do not use this number or common values such as 0. Using just a small set of seeds to instantiate larger state spaces means that there are some initial states that are impossible to reach. This creates some biases if everyone uses such values. A good way to get a seed is to use a "
                },
                {
                  "__type": "CrossRef",
                  "__tag": 4002,
                  "value": "numpy.random.SeedSequence",
                  "reference": {
                    "__type": "RefInfo",
                    "__tag": 4000,
                    "module": "numpy",
                    "version": "*",
                    "kind": "api",
                    "path": "numpy.random.bit_generator:SeedSequence"
                  },
                  "kind": "module"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": ":"
                }
              ]
            },
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> from numpy.random import SeedSequence\n>>> print(SeedSequence().entropy)\n301439351238479871608357552876690613766  # random",
              "execution_status": null
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "random_state",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " parameter in distributions accepts an instance of "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "numpy.random.Generator",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "numpy",
                "version": "*",
                "kind": "api",
                "path": "numpy.random._generator:Generator"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " class, or an integer, which is then used to seed an internal "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "Generator"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " object:"
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> norm.rvs(size=5, random_state=rng)\narray([ 0.47143516, -1.19097569,  1.43270697, -0.3126519 , -0.72058873])  # random",
              "execution_status": null
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "For further info, see "
            },
            {
              "__type": "Link",
              "__tag": 4049,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "NumPy's documentation"
                }
              ],
              "url": "https://numpy.org/doc/stable/reference/random/index.html",
              "title": ""
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "To learn more about the random number samplers implemented in SciPy, see "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "non-uniform random number sampling tutorial <non-uniform-random-number-sampling>",
              "domain": null,
              "role": "ref",
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "quasi monte carlo tutorial",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "docs",
                "path": "tutorial:stats:quasi_monte_carlo"
              },
              "kind": "exists"
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Random number generation"
        }
      ],
      "level": 1,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "All continuous distributions take "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "loc"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "scale"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " as keyword parameters to adjust the location and scale of the distribution, e.g., for the standard normal distribution, the location is the mean and the scale is the standard deviation."
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> norm.stats(loc=3, scale=4, moments=\"mv\")\n(array(3.0), array(16.0))",
              "execution_status": null
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "In many cases, the standardized distribution for a random variable "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "X"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is obtained through the transformation "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "(X - loc) / scale"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". The default values are "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "loc = 0"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "scale = 1"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Smart use of "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "loc"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "scale"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " can help modify the standard distributions in many ways. To illustrate the scaling further, the "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "cdf"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " of an exponentially distributed RV with mean "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "1/\\lambda"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is given by"
            }
          ]
        },
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "F(x) = 1 - \\exp(-\\lambda x)"
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "By applying the scaling rule above, it can be seen that by taking "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "scale  = 1./lambda"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " we get the proper scale."
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> from scipy.stats import expon\n>>> expon.mean(scale=3.)\n3.0",
              "execution_status": null
            }
          ]
        },
        {
          "__type": "Admonition",
          "__tag": 4056,
          "kind": "note",
          "base_type": "note",
          "children": [
            {
              "__type": "AdmonitionTitle",
              "__tag": 4055,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "note Distributions that take shape parameters may"
                }
              ]
            },
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "require more than simple application of "
                },
                {
                  "__type": "InlineCode",
                  "__tag": 4051,
                  "value": "loc"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": " and/or "
                },
                {
                  "__type": "InlineCode",
                  "__tag": 4051,
                  "value": "scale"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": " to achieve the desired form. For example, the distribution of 2-D vector lengths given a constant vector of length "
                },
                {
                  "__type": "InlineMath",
                  "__tag": 4057,
                  "value": "R"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": " perturbed by independent N(0, "
                },
                {
                  "__type": "InlineMath",
                  "__tag": 4057,
                  "value": "\\sigma^2"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": ") deviations in each component is rice("
                },
                {
                  "__type": "InlineMath",
                  "__tag": 4057,
                  "value": "R/\\sigma"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": ", scale= "
                },
                {
                  "__type": "InlineMath",
                  "__tag": 4057,
                  "value": "\\sigma"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "). The first argument is a shape parameter that needs to be scaled along with "
                },
                {
                  "__type": "InlineMath",
                  "__tag": 4057,
                  "value": "x"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "."
                }
              ]
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The uniform distribution is also interesting:"
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> from scipy.stats import uniform\n>>> uniform.cdf([0, 1, 2, 3, 4, 5], loc=1, scale=4)\narray([ 0.  ,  0.  ,  0.25,  0.5 ,  0.75,  1.  ])",
              "execution_status": null
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Finally, recall from the previous paragraph that we are left with the problem of the meaning of "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "norm.rvs(5)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". As it turns out, calling a distribution like this, the first argument, i.e., the 5, gets passed to set the "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "loc"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " parameter. Let's see:"
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> np.mean(norm.rvs(5, size=500))\n5.0098355106969992  # random",
              "execution_status": null
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Thus, to explain the output of the example of the last section: "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "norm.rvs(5)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " generates a single normally distributed random variate with mean "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "loc=5"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", because of the default "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "size=1"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "We recommend that you set "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "loc"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "scale"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " parameters explicitly, by passing the values as keywords rather than as arguments. Repetition can be minimized when calling more than one method of a given RV by using the technique of "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "Freezing a Distribution",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", as explained below."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Shifting and scaling"
        }
      ],
      "level": 1,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "While a general continuous random variable can be shifted and scaled with the "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "loc"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "scale"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " parameters, some distributions require additional shape parameters. For instance, the gamma distribution with density"
            }
          ]
        },
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "\\gamma(x, a) = \\frac{\\lambda (\\lambda x)^{a-1}}{\\Gamma(a)} e^{-\\lambda x}\\;,"
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "requires the shape parameter "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "a"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". Observe that setting "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "\\lambda"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " can be obtained by setting the "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "scale"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " keyword to "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "1/\\lambda"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Let's check the number and name of the shape parameters of the gamma distribution. (We know from the above that this should be 1.)"
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> from scipy.stats import gamma\n>>> gamma.numargs\n1\n>>> gamma.shapes\n'a'",
              "execution_status": null
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Now, we set the value of the shape variable to 1 to obtain the exponential distribution, so that we compare easily whether we get the results we expect."
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> gamma(1, scale=2.).stats(moments=\"mv\")\n(array(2.0), array(4.0))",
              "execution_status": null
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Notice that we can also specify shape parameters as keywords:"
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> gamma(a=1, scale=2.).stats(moments=\"mv\")\n(array(2.0), array(4.0))",
              "execution_status": null
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Shape parameters"
        }
      ],
      "level": 1,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Passing the "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "loc"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "scale"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " keywords time and again can become quite bothersome. The concept of "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "freezing",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " a RV is used to solve such problems."
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> rv = gamma(1, scale=2.)",
              "execution_status": null
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "By using "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "rv"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " we no longer have to include the scale or the shape parameters anymore. Thus, distributions can be used in one of two ways, either by passing all distribution parameters to each method call (such as we did earlier) or by freezing the parameters for the instance of the distribution. Let us check this:"
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> rv.mean(), rv.std()\n(2.0, 2.0)",
              "execution_status": null
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "This is, indeed, what we should get."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Freezing a distribution"
        }
      ],
      "level": 1,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The basic methods "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "pdf"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", and so on, satisfy the usual numpy broadcasting rules. For example, we can calculate the critical values for the upper tail of the t distribution for different probabilities and degrees of freedom."
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> stats.t.isf([0.1, 0.05, 0.01], [[10], [11]])\narray([[ 1.37218364,  1.81246112,  2.76376946],\n       [ 1.36343032,  1.79588482,  2.71807918]])",
              "execution_status": null
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Here, the first row contains the critical values for 10 degrees of freedom and the second row for 11 degrees of freedom (d.o.f.). Thus, the broadcasting rules give the same result of calling "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "isf"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " twice:"
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> stats.t.isf([0.1, 0.05, 0.01], 10)\narray([ 1.37218364,  1.81246112,  2.76376946])\n>>> stats.t.isf([0.1, 0.05, 0.01], 11)\narray([ 1.36343032,  1.79588482,  2.71807918])",
              "execution_status": null
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "If the array with probabilities, i.e., "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "[0.1, 0.05, 0.01]"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and the array of degrees of freedom i.e., "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "[10, 11, 12]"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", have the same array shape, then element-wise matching is used. As an example, we can obtain the 10% tail for 10 d.o.f., the 5% tail for 11 d.o.f. and the 1% tail for 12 d.o.f. by calling"
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> stats.t.isf([0.1, 0.05, 0.01], [10, 11, 12])\narray([ 1.37218364,  1.79588482,  2.68099799])",
              "execution_status": null
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Broadcasting"
        }
      ],
      "level": 1,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Discrete distributions have mostly the same basic methods as the continuous distributions. However "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "pdf"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is replaced by the probability mass function "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "pmf"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", no estimation methods, such as fit, are available, and "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "scale"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is not a valid keyword parameter. The location parameter, keyword "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "loc"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", can still be used to shift the distribution."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The computation of the cdf requires some extra attention. In the case of continuous distribution, the cumulative distribution function is, in most standard cases, strictly monotonic increasing in the bounds (a,b) and has, therefore, a unique inverse. The cdf of a discrete distribution, however, is a step function, hence the inverse cdf, i.e., the percent point function, requires a different definition:"
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": "ppf(q) = min{x : cdf(x) >= q, x integer}",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "For further info, see the docs "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "here<discrete-ppf>",
              "domain": null,
              "role": "ref",
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "We can look at the hypergeometric distribution as an example"
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> from scipy.stats import hypergeom\n>>> [M, n, N] = [20, 7, 12]",
              "execution_status": null
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "If we use the cdf at some integer points and then evaluate the ppf at those cdf values, we get the initial integers back, for example"
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> x = np.arange(4) * 2\n>>> x\narray([0, 2, 4, 6])\n>>> prb = hypergeom.cdf(x, M, n, N)\n>>> prb\narray([  1.03199174e-04,   5.21155831e-02,   6.08359133e-01,\n         9.89783282e-01])\n>>> hypergeom.ppf(prb, M, n, N)\narray([ 0.,  2.,  4.,  6.])",
              "execution_status": null
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "If we use values that are not at the kinks of the cdf step function, we get the next higher integer back:"
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> hypergeom.ppf(prb + 1e-8, M, n, N)\narray([ 1.,  3.,  5.,  7.])\n>>> hypergeom.ppf(prb - 1e-8, M, n, N)\narray([ 0.,  2.,  4.,  6.])",
              "execution_status": null
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Specific points for discrete distributions"
        }
      ],
      "level": 1,
      "target": "discrete_points_label"
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The main additional methods of the not frozen distribution are related to the estimation of distribution parameters:"
            }
          ]
        },
        {
          "__type": "BulletList",
          "__tag": 4053,
          "ordered": false,
          "start": 1,
          "children": [
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "DefList",
                  "__tag": 4033,
                  "children": [
                    {
                      "__type": "DefListItem",
                      "__tag": 4037,
                      "dt": {
                        "__type": "Paragraph",
                        "__tag": 4045,
                        "children": [
                          {
                            "__type": "Text",
                            "__tag": 4046,
                            "value": "fit:   maximum likelihood estimation of distribution parameters, including location"
                          }
                        ]
                      },
                      "dd": [
                        {
                          "__type": "Paragraph",
                          "__tag": 4045,
                          "children": [
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": "and scale"
                            }
                          ]
                        }
                      ]
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "fit_loc_scale: estimation of location and scale when shape parameters are given"
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "nnlf:  negative log likelihood function"
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "expect: calculate the expectation of a function against the pdf or pmf"
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Fitting distributions"
        }
      ],
      "level": 1,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The performance of the individual methods, in terms of speed, varies widely by distribution and method. The results of a method are obtained in one of two ways: either by explicit calculation, or by a generic algorithm that is independent of the specific distribution."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Explicit calculation, on the one hand, requires that the method is directly specified for the given distribution, either through analytic formulas or through special functions in "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "scipy.special"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " or "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "numpy.random"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " for "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "rvs"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". These are usually relatively fast calculations."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The generic methods, on the other hand, are used if the distribution does not specify any explicit calculation. To define a distribution, only one of pdf or cdf is necessary; all other methods can be derived using numeric integration and root finding. However, these indirect methods can be "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "very",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " slow. As an example, "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "rgh = stats.gausshyper.rvs(0.5, 2, 2, 2, size=100)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " creates random variables in a very indirect way and takes about 19 seconds for 100 random variables on my computer, while one million random variables from the standard normal or from the t distribution take just above one second."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Performance issues and cautionary remarks"
        }
      ],
      "level": 1,
      "target": "performance_issues_label"
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The distributions in "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "scipy.stats"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " have recently been corrected and improved and gained a considerable test suite; however, a few issues remain:"
            }
          ]
        },
        {
          "__type": "BulletList",
          "__tag": 4053,
          "ordered": false,
          "start": 1,
          "children": [
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "The distributions have been tested over some range of parameters;   however, in some corner ranges, a few incorrect results may remain."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "The maximum likelihood estimation in "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "fit",
                      "domain": null,
                      "role": null,
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " does not work with   default starting parameters for all distributions and the user   needs to supply good starting parameters. Also, for some   distribution using a maximum likelihood estimator might   inherently not be the best choice."
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Remaining issues"
        }
      ],
      "level": 1,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The next examples shows how to build your own distributions. Further examples show the usage of the distributions and some statistical tests."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Building specific distributions"
        }
      ],
      "level": 1,
      "target": "building_distributions"
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Making continuous distributions is fairly simple."
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> from scipy import stats\n>>> class deterministic_gen(stats.rv_continuous):\n...     def _cdf(self, x):\n...         return np.where(x < 0, 0., 1.)\n...     def _stats(self):\n...         return 0., 0., 0., 0.",
              "execution_status": null
            },
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> deterministic = deterministic_gen(name=\"deterministic\")\n>>> deterministic.cdf(np.arange(-3, 3, 0.5))\narray([ 0.,  0.,  0.,  0.,  0.,  0.,  1.,  1.,  1.,  1.,  1.,  1.])",
              "execution_status": null
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Interestingly,  the "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "pdf"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is now computed automatically:"
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> deterministic.pdf(np.arange(-3, 3, 0.5))\narray([  0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,\n         5.83333333e+04,   4.16333634e-12,   4.16333634e-12,\n         4.16333634e-12,   4.16333634e-12,   4.16333634e-12])",
              "execution_status": null
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Be aware of the performance issues mentioned in "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "performance_issues_label",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "docs",
                "path": "tutorial:stats:probability_distributions"
              },
              "kind": "exists"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". The computation of unspecified common methods can become very slow, since only general methods are called, which, by their very nature, cannot use any specific information about the distribution. Thus, as a cautionary example:"
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> from scipy.integrate import quad\n>>> quad(deterministic.pdf, -1e-1, 1e-1)\n(4.163336342344337e-13, 0.0)",
              "execution_status": null
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "But this is not correct: the integral over this pdf should be 1. Let's make the integration interval smaller:"
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> quad(deterministic.pdf, -1e-3, 1e-3)  # warning removed\n(1.000076872229173, 0.0010625571718182458)",
              "execution_status": null
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "This looks better. However, the problem originated from the fact that the pdf is not specified in the class definition of the deterministic distribution."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Making a continuous distribution, i.e., subclassing "
        },
        {
          "__type": "InlineCode",
          "__tag": 4051,
          "value": "rv_continuous"
        }
      ],
      "level": 2,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "In the following, we use "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "stats.rv_discrete",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " to generate a discrete distribution that has the probabilities of the truncated normal for the intervals centered around the integers."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Strong",
              "__tag": 4048,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "General info"
                }
              ]
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "From the docstring of rv_discrete, "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "help(stats.rv_discrete)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ","
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "\"You can construct an arbitrary discrete rv where P{X=xk} = pk by   passing to the rv_discrete initialization method (through the values=   keyword) a tuple of sequences (xk, pk) which describes only those   values of X (xk) that occur with nonzero probability (pk).\""
                }
              ]
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Next to this, there are some further requirements for this approach to work:"
            }
          ]
        },
        {
          "__type": "BulletList",
          "__tag": 4053,
          "ordered": false,
          "start": 1,
          "children": [
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "The keyword "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "name",
                      "domain": null,
                      "role": null,
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is required."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "The support points of the distribution xk have to be integers."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "The number of significant digits (decimals) needs to be specified."
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "In fact, if the last two requirements are not satisfied, an exception may be raised or the resulting numbers may be incorrect."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Strong",
              "__tag": 4048,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "An example"
                }
              ]
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Let's do the work. First:"
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> npoints = 20   # number of integer support points of the distribution minus 1\n>>> npointsh = npoints // 2\n>>> npointsf = float(npoints)\n>>> nbound = 4   # bounds for the truncated normal\n>>> normbound = (1+1/npointsf) * nbound   # actual bounds of truncated normal\n>>> grid = np.arange(-npointsh, npointsh+2, 1)   # integer grid\n>>> gridlimitsnorm = (grid-0.5) / npointsh * nbound   # bin limits for the truncnorm\n>>> gridlimits = grid - 0.5   # used later in the analysis\n>>> grid = grid[:-1]\n>>> probs = np.diff(stats.truncnorm.cdf(gridlimitsnorm, -normbound, normbound))\n>>> gridint = grid",
              "execution_status": null
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "And, finally, we can subclass "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "rv_discrete"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ":"
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> normdiscrete = stats.rv_discrete(values=(gridint,\n...              np.round(probs, decimals=7)), name='normdiscrete')",
              "execution_status": null
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Now that we have defined the distribution, we have access to all common methods of discrete distributions."
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> print('mean = %6.4f, variance = %6.4f, skew = %6.4f, kurtosis = %6.4f' %\n...       normdiscrete.stats(moments='mvsk'))\nmean = -0.0000, variance = 6.3302, skew = 0.0000, kurtosis = -0.0076",
              "execution_status": null
            },
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> nd_std = np.sqrt(normdiscrete.stats(moments='v'))",
              "execution_status": null
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Strong",
              "__tag": 4048,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "Testing the implementation"
                }
              ]
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Let's generate a random sample and compare observed frequencies with the probabilities."
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> n_sample = 500\n>>> rvs = normdiscrete.rvs(size=n_sample)\n>>> f, l = np.histogram(rvs, bins=gridlimits)\n>>> sfreq = np.vstack([gridint, f, probs*n_sample]).T\n>>> print(sfreq)\n[[-1.00000000e+01  0.00000000e+00  2.95019349e-02]  # random\n [-9.00000000e+00  0.00000000e+00  1.32294142e-01]\n [-8.00000000e+00  0.00000000e+00  5.06497902e-01]\n [-7.00000000e+00  2.00000000e+00  1.65568919e+00]\n [-6.00000000e+00  1.00000000e+00  4.62125309e+00]\n [-5.00000000e+00  9.00000000e+00  1.10137298e+01]\n [-4.00000000e+00  2.60000000e+01  2.24137683e+01]\n [-3.00000000e+00  3.70000000e+01  3.89503370e+01]\n [-2.00000000e+00  5.10000000e+01  5.78004747e+01]\n [-1.00000000e+00  7.10000000e+01  7.32455414e+01]\n [ 0.00000000e+00  7.40000000e+01  7.92618251e+01]\n [ 1.00000000e+00  8.90000000e+01  7.32455414e+01]\n [ 2.00000000e+00  5.50000000e+01  5.78004747e+01]\n [ 3.00000000e+00  5.00000000e+01  3.89503370e+01]\n [ 4.00000000e+00  1.70000000e+01  2.24137683e+01]\n [ 5.00000000e+00  1.10000000e+01  1.10137298e+01]\n [ 6.00000000e+00  4.00000000e+00  4.62125309e+00]\n [ 7.00000000e+00  3.00000000e+00  1.65568919e+00]\n [ 8.00000000e+00  0.00000000e+00  5.06497902e-01]\n [ 9.00000000e+00  0.00000000e+00  1.32294142e-01]\n [ 1.00000000e+01  0.00000000e+00  2.95019349e-02]]",
              "execution_status": null
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Next, we can use a chi-squared test, "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "scipy.stats.chisquare",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "scipy",
                "version": "*",
                "kind": "api",
                "path": "scipy.stats._stats_py:chisquare"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", to test the null hypothesis that the sample is distributed according to our norm-discrete distribution."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The test requires that there are a minimum number of observations in each bin. We combine the tail bins into larger bins so that they contain enough observations."
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> f2 = np.hstack([f[:5].sum(), f[5:-5], f[-5:].sum()])\n>>> p2 = np.hstack([probs[:5].sum(), probs[5:-5], probs[-5:].sum()])\n>>> ch2, pval = stats.chisquare(f2, p2*n_sample)",
              "execution_status": null
            },
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> print('chisquare for normdiscrete: chi2 = %6.3f pvalue = %6.4f' % (ch2, pval))\nchisquare for normdiscrete: chi2 = 12.466 pvalue = 0.4090  # random",
              "execution_status": null
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Conceptually, the test statistic "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "chi2"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is sensitive to deviations between the frequencies of observations and their expected frequencies under the null hypothesis. The p-value is the probability of drawing samples from the hypothesized distribution that would produce a statistic value more extreme than the one we observed. Our statistic value is not very high; in fact, there is a 40.9% chance that the statistic would be higher than 12.466 if we were to draw a sample of the same size from the discrete distribution defined by "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "p2"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". Therefore, the test provides little evidence against the null hypothesis that the sample was drawn from our norm-discrete distribution."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Subclassing "
        },
        {
          "__type": "InlineCode",
          "__tag": 4051,
          "value": "rv_discrete"
        }
      ],
      "level": 2,
      "target": null
    }
  ],
  "local_refs": []
}