Learn R Programming

MixtureInf (version 1.0-1)

rpoismix: Random sample from a mixture of Poissons

Description

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

Usage

rpoismix(n, alpha, lambda)

Arguments

n
number of samples
alpha
vector of mixture probabilities, with length equal to $m$, the desired number of components.
lambda
vector of means of each component.

Value

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

See Also

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

Examples

Run this code
# Draw random samples from a mixture of two equally likely Poisson
# distributions, one with mean = 1, and the other with mean = 10
x <- rpoismix(200, c(0.5, 0.5), c(1,10))
hist(x, probability=TRUE)
lines(density(x), col='red')

Run the code above in your browser using DataLab