rcompound {actuar}  R Documentation 
rcompound
generates random variates from a compound model.
rcomppois
is a simplified version for a common case.
rcompound(n, model.freq, model.sev, SIMPLIFY = TRUE) rcomppois(n, lambda, model.sev, SIMPLIFY = TRUE)
n 
number of observations. If 
model.freq, model.sev 
expressions specifying the frequency and severity simulation models with the number of variates omitted (see details). 
lambda 
Poisson parameter. 
SIMPLIFY 
boolean; if 
rcompound
generates variates from a random variable of the form
S = X_1 + ... X_N,
where N is the frequency random variable and X_1, X_2, … are the severity random variables. The latter are mutually independent, identically distributed and independent from N.
model.freq
and model.sev
specify the simulation models
for the frequency and the severity random variables, respectively. A
model is a complete call to a random number generation function, with
the number of variates omitted. This is similar to
rcomphierarc
, but the calls need not be wrapped into
expression
. Either argument may also be the name of an
object containing an expression, in which case the object will be
evaluated in the evaluation frame to retrieve the expression.
The argument of the random number generation functions for the number
of variates to simulate must be named n
.
rcomppois
generates variates from the common Compound Poisson
model, that is when random variable N is Poisson distributed
with mean lambda
.
When SIMPLIFY = TRUE
, a vector of aggregate amounts S_1,
…, S_n.
When SIMPLIFY = FALSE
, a list of three elements:

vector of aggregate amounts S_1, …, S_n; 

vector of frequencies N_1, …, N_n; 

vector of severities X_1, X_2, …. 
Vincent Goulet vincent.goulet@act.ulaval.ca
rcomphierarc
to simulate from compound hierarchical models.
## Compound Poisson model with gamma severity. rcompound(10, rpois(2), rgamma(2, 3)) rcomppois(10, 2, rgamma(2, 3)) # same ## Frequencies and individual claim amounts along with aggregate ## values. rcomppois(10, 2, rgamma(2, 3), SIMPLIFY = FALSE) ## Wrapping the simulation models into expression() is allowed, but ## not needed. rcompound(10, expression(rpois(2)), expression(rgamma(2, 3))) ## Not run: ## Speed comparison between rcompound() and rcomphierarc(). ## [Also note the simpler syntax for rcompound().] system.time(rcompound(1e6, rpois(2), rgamma(2, 3))) system.time(rcomphierarc(1e6, expression(rpois(2)), expression(rgamma(2, 3)))) ## End(Not run) ## The severity can itself be a compound model. It makes sense ## in such a case to use a zerotruncated frequency distribution ## for the second level model. rcomppois(10, 2, rcompound(rztnbinom(1.5, 0.7), rlnorm(1.2, 1)))