statsmodels.distributions.mixture_rvs.mixture_rvs#
- statsmodels.distributions.mixture_rvs.mixture_rvs(prob, size, dist, kwargs=None, rng=None)[source]#
Sample from a mixture of 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 objects from scipy.stats.
- kwargs
tupleofdicts,optional A tuple of dicts. Each dict in kwargs can have keys loc, scale, and args to be passed to the respective distribution in dist. If not provided, the distribution defaults are used.
- 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.
- Returns:
ndarraySample from the mixture distribution, with length size.
Examples
Say we want 5000 random variables from mixture of normals with two distributions norm(-1,.5) and norm(1,.5) and we want to sample from the first with probability .75 and the second with probability .25.
>>> from scipy import stats >>> prob = [.75,.25] >>> Y = mixture_rvs(prob, 5000, dist=[stats.norm, stats.norm], ... kwargs = (dict(loc=-1,scale=.5),dict(loc=1,scale=.5)))