Skip to main content
`Ctrl`+`K`

# scipy.stats.dirichlet_multinomial

scipy.stats.dirichlet_multinomial = <scipy.stats._multivariate.dirichlet_multinomial_gen object>

  A Dirichlet multinomial random variable.

  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:
    alpha array_like

      The concentration parameters. The number of entries along the last axis determines the dimensionality of the distribution. Each entry must be strictly positive.

    n int or array_like

      The number of trials. Each element must be a strictly positive integer.

    seed{None, int, np.random.RandomState, np.random.Generator}, optional

      Used for drawing random variates. If seed is None, the RandomState singleton is used. If seed is an int, a new `RandomState` instance is used, seeded with seed. If seed is already a `RandomState` or `Generator` instance, then that object is used. Default is None.

  See also

  `scipy.stats.dirichlet`

    The dirichlet distribution.

  `scipy.stats.multinomial`

    The multinomial distribution.

  References

  [1]

  Dirichlet-multinomial distribution, Wikipedia, https://www.wikipedia.org/wiki/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)
      0.08484162895927604

  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)
      0.0

  Get the log of the PMF

      >>> dirichlet_multinomial.logpmf(x, alpha, n)
      -2.4669689491013327

  Get the mean

      >>> dirichlet_multinomial.mean(alpha, n)
      array([1.5, 2. , 2.5])

  Get the variance

      >>> dirichlet_multinomial.var(alpha, n)
      array([1.55769231, 1.84615385, 2.01923077])

  Get the covariance

      >>> dirichlet_multinomial.cov(alpha, n)
      array([[ 1.55769231, -0.69230769, -0.86538462],
             [-0.69230769,  1.84615385, -1.15384615],
             [-0.86538462, -1.15384615,  2.01923077]])

  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)
      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.06493506, 0.02626937])

      >>> 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)

  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.