Learn R Programming

MixtureInf (version 1.0-1)

rexpmix: Random sample from a mixture of exponentials

Description

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

Usage

rexpmix(n, alpha, scale)

Arguments

n
number of samples
alpha
vector of mixture probabilities, with length equal to $m$, the desired number of components.
scale
vector of scales (inverse of rate) of each component.

Value

  • Returns a vector of length $n$ of samples from an $m$-component mixture of univariate exponential 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 exponential
# distributions, one with scale = 1, the other with scale = 0.05
x <- rexpmix(200, c(0.5, 0.5), c(1, 20))
hist(x, probability=TRUE)
lines(density(x), col='red')

Run the code above in your browser using DataLab