Learn R Programming

algebraic.dist (version 0.9.1)

sampler.mixture: Sampler for a mixture distribution.

Description

Returns a function that draws samples from the mixture by first selecting a component according to the mixing weights, then sampling from the selected component.

Usage

# S3 method for mixture
sampler(x, ...)

Value

A function function(n = 1, ...) returning a numeric vector of length n.

Arguments

x

A mixture object.

...

Additional arguments (not used).

Examples

Run this code
m <- mixture(list(normal(0, 1), normal(5, 1)), c(0.5, 0.5))
s <- sampler(m)
set.seed(42)
s(6)

Run the code above in your browser using DataLab