bundles / scipy 1.17.1 / scipy / stats / _multivariate / normal_inverse_gamma_gen
class
scipy.stats._multivariate:normal_inverse_gamma_gen
Signature
class normal_inverse_gamma_gen ( seed = None ) Members
Summary
Normal-inverse-gamma distribution.
Extended Summary
The normal-inverse-gamma distribution is the conjugate prior of a normal distribution with unknown mean and variance.
Parameters
mu, lmbda, a, b: array_likeShape parameters of the distribution. See notes.
seed: {None, int, np.random.RandomState, np.random.Generator}, optionalUsed for drawing random variates. If
seedisNone, the~np.random.RandomStatesingleton is used. Ifseedis an int, a newRandomStateinstance is used, seeded with seed. Ifseedis already aRandomStateorGeneratorinstance, then that object is used. Default isNone.
Methods
pdf(x, s2, mu=0, lmbda=1, a=1, b=1)Probability density function.
logpdf(x, s2, mu=0, lmbda=1, a=1, b=1)Log of the probability density function.
mean(mu=0, lmbda=1, a=1, b=1)Distribution mean.
var(mu=0, lmbda=1, a=1, b=1)Distribution variance.
rvs(mu=0, lmbda=1, a=1, b=1, size=None, random_state=None)Draw random samples.
Notes
The probability density function of normal_inverse_gamma is:
where all parameters are real and finite, and , , , and .
Methods normal_inverse_gamma.pdf and normal_inverse_gamma.logpdf accept x and s2 for arguments and . All methods accept mu, lmbda, a, and b for shape parameters , , , and , respectively.
Examples
Suppose we wish to investigate the relationship between the normal-inverse-gamma distribution and the inverse gamma distribution.import numpy as np from scipy import stats import matplotlib.pyplot as plt rng = np.random.default_rng(527484872345) mu, lmbda, a, b = 0, 1, 20, 20 norm_inv_gamma = stats.normal_inverse_gamma(mu, lmbda, a, b) inv_gamma = stats.invgamma(a, scale=b)✓
_, s2 = norm_inv_gamma.rvs(size=10000, random_state=rng) bins = np.linspace(s2.min(), s2.max(), 50)✓
plt.hist(s2, bins=bins, density=True, label='Frequency density')
✗s2 = np.linspace(s2.min(), s2.max(), 300)
✓plt.plot(s2, inv_gamma.pdf(s2), label='PDF') plt.xlabel(r'$\sigma^2$') plt.ylabel('Frequency density / PMF')✗
plt.show()
✓
from scipy.integrate import quad_vec from scipy import integrate s2 = np.linspace(0.5, 3, 6) res = quad_vec(lambda x: norm_inv_gamma.pdf(x, s2), -np.inf, np.inf)[0] np.allclose(res, inv_gamma.pdf(s2))✓
x, s2 = norm_inv_gamma.rvs(size=10000, random_state=rng)
✓x.mean(), s2.mean()
✗norm_inv_gamma.mean()
✓x.var(ddof=1), s2.var(ddof=1) norm_inv_gamma.var()✓
See also
- invgamma
- norm
Aliases
-
scipy.stats._multivariate.normal_inverse_gamma_gen