statsmodels.distributions.mixture_rvs.mv_mixture_rvs#

statsmodels.distributions.mixture_rvs.mv_mixture_rvs(prob, size, dist, nvars, rng=None, **kwargs)[source]#

Sample from a mixture of multivariate distributions.

Parameters:
probarray_like

Probability of sampling from each distribution in dist

sizeint

The length of the returned sample.

distarray_like

An iterable of distributions instances with callable method rvs.

nvarsint

dimension of the multivariate distribution, could be inferred instead

rngint, array_like of int, numpy.random.Generator, or numpy.random.RandomState, optional

If rng is None, the legacy global (singleton) RandomState provided by numpy.random is used; this behavior is deprecated and will change to creating a new Generator using fresh entropy from the operating system in a future release. If rng is an int or array of ints, a new RandomState instance is created, seeded with rng. If rng is already a Generator or RandomState instance, that instance is used.

**kwargs

Ignored.

Returns:
ndarray

Sample from the mixture of multivariate distributions, with shape (size, nvars).

Examples

Say we want 2000 random variables from mixture of normals with two multivariate normal distributions, and we want to sample from the first with probability .4 and the second with probability .6.

import statsmodels.sandbox.distributions.mv_normal as mvd

cov3 = np.array([[ 1. , 0.5 , 0.75],

[ 0.5 , 1.5 , 0.6 ], [ 0.75, 0.6 , 2. ]])

mu = np.array([-1, 0.0, 2.0]) mu2 = np.array([4, 2.0, 2.0]) mvn3 = mvd.MVNormal(mu, cov3) mvn32 = mvd.MVNormal(mu2, cov3/2., 4) rvs = mix.mv_mixture_rvs([0.4, 0.6], 2000, [mvn3, mvn32], 3)