sampler.mixture: Sampler for a mixture distribution.

View source: R/mixture.R

sampler.mixtureR Documentation

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 class 'mixture'
sampler(x, ...)

Arguments

x

A mixture object.

...

Additional arguments (not used).

Value

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

Examples

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

algebraic.dist documentation built on Feb. 27, 2026, 5:06 p.m.