
Last chance! 50% off unlimited learning
Sale ends in
UNU.RAN random variate generator for a finite mixture of continuous or
discrete distributions.
The components are given as unuran
objects.
[Universal] -- Composition Method.
mixt.new(prob, comp, inversion=FALSE)
An object of class "unuran"
.
weights of mixture (“probabilities”); these must be non-negative numbers but need not sum to 1. (numeric vector)
components of mixture.
(list of S4 object of class "unuran"
)
whether inversion method should be used. (boolean)
Josef Leydold and Wolfgang H\"ormann unuran@statmath.wu.ac.at.
Given a set of probability density functions
Function mixt.new
creates an unuran
object for a finite
mixture of continuous or discrete univariate distributions.
It can be used to draw samples of a continuous random variate using
ur
.
The weights prob
must be a vector of non-negative numbers (not
all equal to 0) but need not sum to 1.
comp
is a list of "unuran"
generator objects. Each of
which must sample from a continuous or discrete univariate
distribution.
If inversion
is TRUE
, then the inversion method is used
for sampling from the mixture distribution.
However, the following conditions must be satisfied:
Each component (unuran
object) must use implement an
inversion method (i.e., the quantile funtion uq
must
work).
The domains of the components must not overlapping.
The components must be order with respect to their domains.
If one of these conditions is violated, then initialization of the mixture object fails.
The setup time is fast, whereas its marginal generation times strongly depend on the average generation times of its components.
W. H\"ormann, J. Leydold, and G. Derflinger (2004): Automatic Nonuniform Random Variate Generation. Springer-Verlag, Berlin Heidelberg. See Section 2.3 (Composition).
ur
, uq
,
unuran.new
,
unuran
.
## Create a mixture of an Exponential and a Half-normal distribution
unr1 <- unuran.new(udnorm(lb=-Inf, ub=0))
unr2 <- unuran.new(udexp())
mix <- mixt.new( c(1,1), c(unr1, unr2) )
x <- ur(mix,100)
## Now use inversion method:
## It is important that
## 1. we use a inversion for each component
## 2. the domains to not overlap
## 3. the components are ordered with respect to their domains
unr1 <- pinvd.new(udnorm(lb=-Inf, ub=0))
unr2 <- pinvd.new(udexp())
mix <- mixt.new( c(1,1), c(unr1, unr2), inversion=TRUE )
x <- ur(mix,100)
## We also can compute the inverse distribution function
##x <- uq(mix,0.90)
## Create a mixture of Exponential and Geometric distrbutions
unr1 <- unuran.new(udexp())
unr2 <- unuran.new(udgeom(0.7))
mix <- mixt.new( c(0.6,0.4), c(unr1, unr2) )
x <- ur(mix,100)
Run the code above in your browser using DataLab