{ } Raw JSON

bundles / scipy 1.17.1 / scipy / stats / _multivariate / dirichlet_multinomial_gen

class

scipy.stats._multivariate:dirichlet_multinomial_gen

source: /scipy/stats/_multivariate.py :6769

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
Get the PMF
n = 6  # number of trials
alpha = [3, 4, 5]  # concentration parameters
x = [1, 2, 3]  # counts
dirichlet_multinomial.pmf(x, alpha, n)
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)
Get the log of the PMF
dirichlet_multinomial.logpmf(x, alpha, n)
Get the mean
dirichlet_multinomial.mean(alpha, n)
Get the variance
dirichlet_multinomial.var(alpha, n)
Get the covariance
dirichlet_multinomial.cov(alpha, n)
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)
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)
dirichlet_multinomial.cov(alpha, n).shape  # both covariance matrices
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

See also

scipy.stats.dirichlet

The dirichlet distribution.

scipy.stats.multinomial

The multinomial distribution.

Aliases

  • scipy.stats._multivariate.dirichlet_multinomial_gen