{
  "__type": "IngestedDoc",
  "__tag": 4010,
  "_content": {
    "Notes": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The probability density function of "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "normal_inverse_gamma",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is:"
            }
          ]
        },
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "f(x, \\sigma^2; \\mu, \\lambda, \\alpha, \\beta) =\n    \\frac{\\sqrt{\\lambda}}{\\sqrt{2 \\pi \\sigma^2}}\n    \\frac{\\beta^\\alpha}{\\Gamma(\\alpha)}\n    \\left( \\frac{1}{\\sigma^2} \\right)^{\\alpha + 1}\n    \\exp \\left(- \\frac{2 \\beta + \\lambda (x - \\mu)^2} {2 \\sigma^2} \\right)"
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "where all parameters are real and finite, and "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "\\sigma^2 > 0"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "\\lambda > 0"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "\\alpha > 0"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", and "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "\\beta > 0"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Methods "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "normal_inverse_gamma.pdf"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "normal_inverse_gamma.logpdf"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " accept "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "x",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "s2",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": null,
                "version": null,
                "kind": "local",
                "path": "s2"
              },
              "kind": "local"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " for arguments "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "x"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "\\sigma^2"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". All methods accept "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "mu",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": null,
                "version": null,
                "kind": "local",
                "path": "mu"
              },
              "kind": "local"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "lmbda",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": null,
                "version": null,
                "kind": "local",
                "path": "lmbda"
              },
              "kind": "local"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "a",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": null,
                "version": null,
                "kind": "local",
                "path": "a"
              },
              "kind": "local"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", and "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "b",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": null,
                "version": null,
                "kind": "local",
                "path": "b"
              },
              "kind": "local"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " for shape parameters "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "\\mu"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "\\lambda"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "\\alpha"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", and "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "\\beta"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", respectively."
            }
          ]
        },
        {
          "__type": "Admonition",
          "__tag": 4056,
          "kind": "versionadded",
          "base_type": "neutral",
          "children": [
            {
              "__type": "AdmonitionTitle",
              "__tag": 4055,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "versionadded 1.15"
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Warns": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Raises": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Yields": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Methods": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Parameters",
          "__tag": 4026,
          "children": [
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "pdf(x, s2, mu=0, lmbda=1, a=1, b=1)",
              "annotation": "",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Probability density function."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "logpdf(x, s2, mu=0, lmbda=1, a=1, b=1)",
              "annotation": "",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Log of the probability density function."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "mean(mu=0, lmbda=1, a=1, b=1)",
              "annotation": "",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Distribution mean."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "var(mu=0, lmbda=1, a=1, b=1)",
              "annotation": "",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Distribution variance."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "rvs(mu=0, lmbda=1, a=1, b=1, size=None, random_state=None)",
              "annotation": "",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Draw random samples."
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Returns": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Normal-inverse-gamma distribution."
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Receives": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Warnings": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Attributes": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Parameters": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Parameters",
          "__tag": 4026,
          "children": [
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "mu, lmbda, a, b",
              "annotation": "array_like",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Shape parameters of the distribution. See notes."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "seed",
              "annotation": "{None, int, np.random.RandomState, np.random.Generator}, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Used for drawing random variates. If "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "seed"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "None",
                      "domain": null,
                      "role": null,
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", the "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "~np.random.RandomState",
                      "domain": null,
                      "role": null,
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " singleton is used. If "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "seed"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is an int, a new "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "RandomState"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " instance is used, seeded with seed. If "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "seed"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is already a "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "RandomState"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " or "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "Generator"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " instance, then that object is used. Default is "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "None",
                      "domain": null,
                      "role": null,
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "."
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Extended Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The normal-inverse-gamma distribution is the conjugate prior of a normal distribution with unknown mean and variance."
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Other Parameters": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    }
  },
  "_ordered_sections": [
    "Summary",
    "Extended Summary",
    "Parameters",
    "Attributes",
    "Methods",
    "Returns",
    "Yields",
    "Receives",
    "Other Parameters",
    "Raises",
    "Warns",
    "Warnings",
    "Notes"
  ],
  "item_file": "/scipy/stats/_multivariate.py",
  "item_line": 7732,
  "item_type": "class",
  "aliases": [
    "scipy.stats._multivariate.normal_inverse_gamma_gen"
  ],
  "example_section_data": {
    "__type": "Section",
    "__tag": 4015,
    "children": [
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "Suppose we wish to investigate the relationship between the\nnormal-inverse-gamma distribution and the inverse gamma distribution.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "import numpy as np\nfrom scipy import stats\nimport matplotlib.pyplot as plt\nrng = np.random.default_rng(527484872345)\nmu, lmbda, a, b = 0, 1, 20, 20\nnorm_inv_gamma = stats.normal_inverse_gamma(mu, lmbda, a, b)\ninv_gamma = stats.invgamma(a, scale=b)\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nOne approach is to compare the distribution of the `s2` elements of\nrandom variates against the PDF of an inverse gamma distribution.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "_, s2 = norm_inv_gamma.rvs(size=10000, random_state=rng)\nbins = np.linspace(s2.min(), s2.max(), 50)\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "plt.hist(s2, bins=bins, density=True, label='Frequency density')\n",
        "execution_status": "failure"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "s2 = np.linspace(s2.min(), s2.max(), 300)\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "plt.plot(s2, inv_gamma.pdf(s2), label='PDF')\nplt.xlabel(r'$\\sigma^2$')\nplt.ylabel('Frequency density / PMF')\n",
        "execution_status": "failure"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "plt.show()\n",
        "execution_status": "success"
      },
      {
        "__type": "Figure",
        "__tag": 4024,
        "value": {
          "__type": "RefInfo",
          "__tag": 4000,
          "module": "scipy",
          "version": "1.17.1",
          "kind": "assets",
          "path": "fig-aebabb4490d05869.png"
        }
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nSimilarly, we can compare the marginal distribution of `s2` against\nan inverse gamma distribution.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "from scipy.integrate import quad_vec\nfrom scipy import integrate\ns2 = np.linspace(0.5, 3, 6)\nres = quad_vec(lambda x: norm_inv_gamma.pdf(x, s2), -np.inf, np.inf)[0]\nnp.allclose(res, inv_gamma.pdf(s2))\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nThe sample mean is comparable to the mean of the distribution.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "x, s2 = norm_inv_gamma.rvs(size=10000, random_state=rng)\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "x.mean(), s2.mean()\n",
        "execution_status": "failure"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "norm_inv_gamma.mean()\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nSimilarly, for the variance:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "x.var(ddof=1), s2.var(ddof=1)\nnorm_inv_gamma.var()\n",
        "execution_status": "success"
      }
    ],
    "title": [],
    "level": 0,
    "target": null
  },
  "see_also": [
    {
      "__type": "SeeAlsoItem",
      "__tag": 4028,
      "name": {
        "__type": "CrossRef",
        "__tag": 4002,
        "value": "invgamma",
        "reference": {
          "__type": "RefInfo",
          "__tag": 4000,
          "module": "current-module",
          "version": "current-version",
          "kind": "to-resolve",
          "path": "invgamma"
        },
        "kind": "module"
      },
      "descriptions": [],
      "type": null
    },
    {
      "__type": "SeeAlsoItem",
      "__tag": 4028,
      "name": {
        "__type": "CrossRef",
        "__tag": 4002,
        "value": "norm",
        "reference": {
          "__type": "RefInfo",
          "__tag": 4000,
          "module": "current-module",
          "version": "current-version",
          "kind": "to-resolve",
          "path": "norm"
        },
        "kind": "module"
      },
      "descriptions": [],
      "type": null
    }
  ],
  "signature": {
    "__type": "SignatureNode",
    "__tag": 4029,
    "kind": "function",
    "parameters": [
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "seed",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "None"
      }
    ],
    "return_annotation": {
      "__type": "Empty",
      "__tag": 4031
    },
    "target_name": "normal_inverse_gamma_gen"
  },
  "references": [
    ".. [1] Normal-inverse-gamma distribution, Wikipedia,",
    "       https://en.wikipedia.org/wiki/Normal-inverse-gamma_distribution"
  ],
  "qa": "scipy.stats._multivariate:normal_inverse_gamma_gen",
  "arbitrary": [],
  "local_refs": [
    "a",
    "a=1",
    "b",
    "b=1",
    "b=1)",
    "lmbda",
    "lmbda=1",
    "logpdf(x",
    "mean(mu=0",
    "mu",
    "mu=0",
    "pdf(x",
    "random_state=None)",
    "rvs(mu=0",
    "s2",
    "seed",
    "size=None",
    "var(mu=0"
  ]
}