UNU.RAN random variate generator for a finite mixture of continuous or
The components are given as
[Universal] – Composition Method.
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
whether inversion method should be used. (boolean)
Given a set of probability density functions p_1(x),…,p_n(x) (called the mixture components) and weights w_1,…,w_n such that w_i >= 0 and w_1+…+w_n=1, the sum
q(x) = w_1*p_1(x) + … + w_n*p_n(x)
is called the mixture density.
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
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
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
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.
An object of class
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
Moreover, none of these components must be packed
Josef Leydold and Wolfgang H\"ormann [email protected].
W. H\"ormann, J. Leydold, and G. Derflinger (2004): Automatic Nonuniform Random Variate Generation. Springer-Verlag, Berlin Heidelberg. See Section 2.3 (Composition).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
## 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.