rvmix {rv}R Documentation

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

Details

If an index is given, prob is ignored.

Value

A random variable.

Author(s)

Jouni Kerman kerman@stat.columbia.edu http://www.stat.columbia.edu/~kerman

References

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

Examples

  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)

[Package rv version 0.949 Index]