Learn R Programming

rv (version 0.949)

rvmix: Generate Random Variables from a Mixture Distribution

Description

Generates a random variable from a mixture of given random variables.

Usage

rvmix(n=1, prob=NULL, index=NULL, components=list())

Arguments

n
number of independent draws to output
prob
probabilities of the components (or weights, will be normalized)
index
(optional) index random variable, giving the distribution of indices
components
a list of the component random variables

Value

  • A random variable.

Details

If an index is given, prob is ignored.

References

Kerman, Jouni and Gelman, Andrew. Manipulating and Summarizing Posterior Simulations Using Random Variable Objects. Technical report, Columbia University, New York.

Examples

Run this code
comp <- list(rvnorm(mean=0), rvnorm(mean=10)) # Normal components of a mixture distribution
  rvmix(prob=c(95,5), components=comp) # 5 per cent comes from N(10,1)

Run the code above in your browser using DataLab