mixt.new {Runuran} | R Documentation |
UNU.RAN generator for finite mixture of distributions
Description
UNU.RAN random variate generator for a finite mixture of continuous or
discrete distributions.
The components are given as unuran
objects.
[Universal] – Composition Method.
Usage
mixt.new(prob, comp, inversion=FALSE)
Arguments
prob |
weights of mixture (“probabilities”); these must be non-negative numbers but need not sum to 1. (numeric vector) |
comp |
components of mixture.
(list of S4 object of class |
inversion |
whether inversion method should be used. (boolean) |
Details
Given a set of probability density functions
p_1(x),\dots,p_n(x)
(called the mixture components) and weights
w_1,\dots,w_n
such that w_i \ge 0
and
\sum w_i = 1
,
the sum
q(x) = \sum_{i=1}^n \, w_i \, p_i(x)
is called the mixture density.
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 funtionuq
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.
Value
An object of class "unuran"
.
Note
Each component in comp
must correspond to a continuous or
discrete univariate distribution. In particular this also includes
mixtures of distributions. Thus mixtures can also be defined
recursively.
Moreover, none of these components must be packed
(see unuran.packed
).
Author(s)
Josef Leydold and Wolfgang H\"ormann unuran@statmath.wu.ac.at.
References
W. H\"ormann, J. Leydold, and G. Derflinger (2004): Automatic Nonuniform Random Variate Generation. Springer-Verlag, Berlin Heidelberg. See Section 2.3 (Composition).
See Also
ur
, uq
,
unuran.new
,
unuran
.
Examples
## 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)