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 length(n) > 1, the length is taken to be the number required.

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 FALSE the frequency and severity variates are returned along with the aggregate variates.

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, … 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.

Value

When SIMPLIFY = TRUE, a vector of aggregate amounts S_1, …, S_n.

When SIMPLIFY = FALSE, a list of three elements:

aggregate

vector of aggregate amounts S_1, …, S_n;

frequency

vector of frequencies N_1, …, N_n;

severity

vector of severities X_1, X_2, ….

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)))

[Package actuar version 3.1-4 Index]