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{
None,numpy.random.Generator,numpy.random.RandomState},optional If rng is None, the global (legacy) NumPy random state is used. If rng is already a
GeneratororRandomStateinstance, that instance is used.- kwargs
tupleofdicts,optional ignored
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)