rcompound {actuar} | R Documentation |
Simulation from Compound Models
Description
rcompound
generates random variates from a compound model.
rcomppois
is a simplified version for a common case.
Usage
rcompound(n, model.freq, model.sev, SIMPLIFY = TRUE)
rcomppois(n, lambda, model.sev, SIMPLIFY = TRUE)
Arguments
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 |
Details
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,
\dots
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 parent 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
.
Value
When SIMPLIFY = TRUE
, a vector of aggregate amounts S_1,
\dots, S_n
.
When SIMPLIFY = FALSE
, a list of three elements:
aggregate |
vector of aggregate amounts |
frequency |
vector of frequencies |
severity |
vector of severities |
Author(s)
Vincent Goulet vincent.goulet@act.ulaval.ca
See Also
rcomphierarc
to simulate from compound hierarchical models.
Examples
## 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 zero-truncated frequency distribution
## for the second level model.
rcomppois(10, 2,
rcompound(rztnbinom(1.5, 0.7), rlnorm(1.2, 1)))