Learn R Programming

MixtureInf (version 1.0-1)

rbinommix: Random sample from a mixture of binomials

Description

Generate a random sample for a mixture of univariate binomial distributions.

Usage

rbinommix(n, alpha, prob, size)

Arguments

n
number of samples
alpha
vector of mixture probabilities, with length equal to $m$, the desired number of components.
prob
vector of probabilities of success of each component.
size
number of trials

Value

  • Returns a vector of length $n$ of samples from an $m$-component mixture of univariate binomial distributions.

See Also

Functions for mixtures of other standard distributions, such as rnormmix for the normal and rpoismix for the Poisson distribution.

Examples

Run this code
# Draw random samples from a mixture of two equally likely binomials,
# one with p(success) = 0.1, the other with p(success) = 0.9
x <- rbinommix(200, c(0.5, 0.5), c(0.1, 0.9), 16)
hist(x, probability=TRUE)
lines(density(x), col='red')

Run the code above in your browser using DataLab