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
- size
int The length of the returned sample.
- distarray_like
An iterable of distributions instances with callable method rvs.
- nvars
int dimension of the multivariate distribution, could be inferred instead
- rng
int, array_likeofint,numpy.random.Generator,ornumpy.random.RandomState,optional If rng is None, the legacy global (singleton)
RandomStateprovided bynumpy.randomis used; this behavior is deprecated and will change to creating a newGeneratorusing fresh entropy from the operating system in a future release. If rng is an int or array of ints, a newRandomStateinstance is created, seeded with rng. If rng is already aGeneratororRandomStateinstance, that instance is used.- **kwargs
Ignored.
- Returns:
ndarraySample 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)