bundles / scipy 2.0.0.dev0+git20260907.41eeb59 / scipy / stats / _multivariate / dirichlet_multinomial_gen
class
scipy.stats._multivariate:dirichlet_multinomial_gen
source: build-install/usr/lib/python3.14/site-packages/scipy/stats/_multivariate.py:6774
Signature
class dirichlet_multinomial_gen(seed = None)Members
Summary
A Dirichlet multinomial random variable.
Extended Summary
The Dirichlet multinomial distribution is a compound probability distribution: it is the multinomial distribution with number of trials n and class probabilities p randomly sampled from a Dirichlet distribution with concentration parameters alpha.
Parameters
%(_dirichlet_mn_doc_default_callparams)s%(_doc_random_state)s
Methods
logpmf(x, alpha, n):Log of the probability mass function.
pmf(x, alpha, n):Probability mass function.
mean(alpha, n):Mean of the Dirichlet multinomial distribution.
var(alpha, n):Variance of the Dirichlet multinomial distribution.
cov(alpha, n):The covariance of the Dirichlet multinomial distribution.
Examples
from scipy.stats import dirichlet_multinomial
✓n = 6 # number of trials alpha = [3, 4, 5] # concentration parameters x = [1, 2, 3] # counts✓
dirichlet_multinomial.pmf(x, alpha, n)
✗np.float64(0.08484162895927579)If the sum of category counts does not equal the number of trials, the probability mass is zero.
dirichlet_multinomial.pmf(x, alpha, n=7)
✗np.float64(0.0)Get the log of the PMF
dirichlet_multinomial.logpmf(x, alpha, n)
✗np.float64(-2.466968949101336)Get the mean
dirichlet_multinomial.mean(alpha, n)
✓array([1.5, 2. , 2.5])Get the variance
dirichlet_multinomial.var(alpha, n)
✗array([1.55769, 1.84615, 2.01923])Get the covariance
dirichlet_multinomial.cov(alpha, n)
✗array([[ 1.55769, -0.69231, -0.86538],
[-0.69231, 1.84615, -1.15385],
[-0.86538, -1.15385, 2.01923]])
Alternatively, the object may be called (as a function) to fix the
`alpha` and `n` parameters, returning a "frozen" Dirichlet multinomial
random variable.
dm = dirichlet_multinomial(alpha, n)
✓dm.pmf(x)
✗np.float64(0.08484162895927579)All methods are fully vectorized. Each element of `x` and `alpha` is a vector (along the last axis), each element of `n` is an integer (scalar), and the result is computed element-wise.
x = [[1, 2, 3], [4, 5, 6]] alpha = [[1, 2, 3], [4, 5, 6]] n = [6, 15]✓
dirichlet_multinomial.pmf(x, alpha, n)
✗array([0.06494, 0.02627])
dirichlet_multinomial.cov(alpha, n).shape # both covariance matrices
✓(2, 3, 3)Broadcasting according to standard NumPy conventions is supported. Here, we have four sets of concentration parameters (each a two element vector) for each of three numbers of trials (each a scalar).
alpha = [[3, 4], [4, 5], [5, 6], [6, 7]] n = [[6], [7], [8]] dirichlet_multinomial.mean(alpha, n).shape✓
(3, 4, 2)
See also
- scipy.stats.dirichlet
The dirichlet distribution.
- scipy.stats.multinomial
The multinomial distribution.
Aliases
scipy.stats._multivariate.dirichlet_multinomial_gen