| rmixture {actuar} | R Documentation |
Generate random variates from a discrete mixture of distributions.
rmixture(n, probs, models)
n |
number of random variates to generate. If |
probs |
numeric non-negative vector specifying the probability
for each model; is internally normalized to sum 1. Infinite
and missing values are not allowed. Values are recycled as necessary
to match the length of |
models |
vector of expressions specifying the simulation models
with the number of variates omitted (see details). Models are
recycled as necessary to match the length of |
rmixture generates variates from a discrete mixture, that is
random variable with a probability density function of the form
f(x) = p_1 f_1(x) + ... + p_n f_n(x),
where f_1, …, f_n are densities and p_1 + … + p_n = 1.
The values in probs will be internally normalized to be
used as probabilities p_1 + … + p_n.
The specification of simulation models uses the syntax of
rcomphierarc. Models f_1, …, f_n are expressed in a
semi-symbolic fashion using an object of mode
expression where each element is a complete call
to a random number generation function, with the number of variates
omitted.
The argument of the random number generation functions for the number
of variates to simulate must be named n.
A vector of random deviates from the mixture with density f(x).
Vincent Goulet vincent.goulet@act.ulaval.ca
rcompound to simulate from compound models.
rcomphierarc to simulate from compound hierarchical models.
## Mixture of two exponentials (with means 1/3 and 1/7) with equal
## probability.
rmixture(10, 0.5, expression(rexp(3), rexp(7)))
rmixture(10, 42, expression(rexp(3), rexp(7))) # same
## Mixture of two lognormals with different probabilities.
rmixture(10, probs = c(0.554, 0.446),
models = expression(rlnorm(3.575, 0.637),
rlnorm(4.555, 0.265)))