composite {distributionsrd}R Documentation

The two- or three-composite distribution

Description

Density, distribution function, quantile function, raw moments and random generation for the two- or three-composite distribution.

Usage

dcomposite(x, dist, coeff, startc = c(1, 1), log = FALSE)

pcomposite(q, dist, coeff, startc = c(1, 1), log.p = FALSE, lower.tail = TRUE)

qcomposite(p, dist, coeff, startc = c(1, 1), log.p = FALSE, lower.tail = TRUE)

mcomposite(
  r = 0,
  truncation = 0,
  dist,
  coeff,
  startc = c(1, 1),
  lower.tail = TRUE
)

rcomposite(n, dist, coeff, startc = c(1, 1))

Arguments

x, q

vector of quantiles

dist

character vector denoting the distribution of the first-, second- (and third) component respectively. If only two components are provided, the distribution reduces to the two-component distribution.

coeff

named numeric vector holding the coefficients of the first-, second- (and third) component, predeced by coeff1., coeff2. (and coeff3.), respectively. Coefficients for the last component do not have to be provided for the two-component distribution and will be disregarded.

startc

starting values for the lower and upper cutoff, defaults to c(1,1).

log, log.p

logical; if TRUE, probabilities p are given as log(p).

lower.tail

logical; if TRUE (default), probabilities (moments) are P[X ≤q x] (E[x^r|X ≤q y]), otherwise, P[X > x] (E[x^r|X > y])

p

vector of probabilities

r

rth raw moment of the Pareto distribution

truncation

lower truncation parameter

n

number of observations

Details

These derivations are based on the two-composite distribution proposed by (Bakar et al. 2015). Probability Distribution Function:

f(x) = \{ \begin{array}{lrl} \frac{α_1}{1 + α_1 + α_2} \frac{m_1(x)}{M_1(c_1)} & { if} & 0<x ≤q c_1 \\ \frac{1}{1 + α_1 + α_2} \frac{m_2(x)}{M_2(c_2) - M_2(c_1)} & { if} & c_1<x ≤q c_2 \\ \frac{α_2}{1 + α_1 + α_2} \frac{m_3(x)}{1-M_3(c_2)} & { if} & c_{2}<x < ∞ \\ \end{array} .

Cumulative Distribution Function:

\{ \begin{array}{lrl} \frac{α_1}{1 + α_1 + α_2} \frac{M_1(x)}{M_1(c_1)} & { if} & 0<x ≤q c_1 \\ \frac{α_1}{1 + α_1 + α_2} + \frac{1}{1 + α_1 + α_2}\frac{M_2(x) - M_2(c_1)}{M_2(c_2) - M_2(c_1)} & { if} & c_1<x ≤q c_2 \\ \frac{1+α_1}{1 + α_1 + α_2} + \frac{α_2}{1 + α_1 + α_2} \frac{M_3(x) - M_3(c_2)}{1-M_3(c_2)} & { if} & c_{2}<x < ∞ \\ \end{array} .

Quantile function

Q(p) = \{ \begin{array}{lrl} Q_1( \frac{1 + α_1 + α_2}{α_1} p M_1(c_1) ) & { if} & 0<x ≤q \frac{α_1}{1 + α_1 + α_2} \\ Q_2[((p - \frac{α_1}{1 + α_1 + α_2})(1 + α_1 + α_2)(M_2(c_2) - M_2(c_1))) + M_2(c_1)] & { if} & \frac{α_1}{1 + α_1 + α_2}<x ≤q \frac{1+α_1}{1 + α_1 + α_2} \\ Q_3[((p - \frac{1+α_1}{1 + α_1 + α_2})(\frac{1 + α_1 + α_2}{α_2})(1 - M_3(c_2))) + M_3(c_2)] & { if} & \frac{1+α_1}{1 + α_1 + α_2}<x < ∞ \\ \end{array} .

The lower y-bounded r-th raw moment of the distribution equals

μ_y^r = \{ \begin{array}{lrl} \frac{α_1}{1 + α_1 + α_2}\frac{ (μ_1)_y^r - (μ_1)_{c_1}^r}{M_1(c_1)} + \frac{1}{1 + α_1 + α_2}\frac{ (μ_2)_{c_1}^r - (μ_2)_{c_2}^r }{M_2(c_2) - M_2(c_1)} + \frac{α_2}{1 + α_1 + α_2} \frac{(μ_3)_y^r}{1-M_3(c_2)} & { if} & 0< y ≤q c_2 \\ \frac{1}{1 + α_1 + α_2} \frac{(μ_2)_y^r - (μ_2)_{c_2}^r }{M_2(c_2) - M_2(c_1)} + \frac{α_2}{1 + α_1 + α_2} \frac{(μ_3)_{c_2}^r}{1-M_3(c_2)} & { if} & c_1< y ≤q c_2\\ \frac{α_2}{1 + α_1 + α_2} \frac{(μ_3)_y^r}{1-M_3(c_2)} & { if} & c_2< y < ∞ \\ \end{array} .

Value

dcomposite returns the density, pcomposite the distribution function, qcomposite the quantile function, mcomposite the rth moment of the distribution and rcomposite generates random deviates.

The length of the result is determined by n for rcomposite, and is the maximum of the lengths of the numerical arguments for the other functions.

References

Bakar SA, Hamzah N, Maghsoudi M, Nadarajah S (2015). “Modeling loss data using composite models.” Insurance: Mathematics and Economics, 61, 146–154.

Examples


#' ## Three-component distribution
dist <- c("invpareto", "lnorm", "pareto")
coeff <- c(coeff2.meanlog = -0.5, coeff2.sdlog = 0.5, coeff3.k = 1.5, coeff1.k = 1.5)

# Compare density with the Double-Pareto Lognormal distribution
plot(x = seq(0, 5, length.out = 1e3), y = dcomposite(x = seq(0, 5, length.out = 1e3),
dist = dist, coeff = coeff))
lines(x = seq(0, 5, length.out = 1e3), y = ddoubleparetolognormal(x = seq(0, 5, length.out = 1e3)))

# Demonstration of log functionality for probability and quantile function
qcomposite(pcomposite(2, dist = dist, coeff = coeff, log.p = TRUE), dist = dist,
coeff = coeff, log.p = TRUE)

# The zeroth truncated moment is equivalent to the probability function
pcomposite(2, dist = dist, coeff = coeff)
mcomposite(truncation = 2, dist = dist, coeff = coeff)

# The (truncated) first moment is equivalent to the mean of a (truncated) random sample,
#for large enough samples.
coeff <- c(coeff2.meanlog = -0.5, coeff2.sdlog = 0.5, coeff3.k = 3, coeff1.k = 1.5)
x <- rcomposite(1e5, dist = dist, coeff = coeff)

mean(x)
mcomposite(r = 1, lower.tail = FALSE, dist = dist, coeff = coeff)

sum(x[x > quantile(x, 0.1)]) / length(x)
mcomposite(r = 1, truncation = quantile(x, 0.1), lower.tail = FALSE, dist = dist, coeff = coeff)

## Two-component distribution
dist <- c("lnorm", "pareto")
coeff <- coeff <- c(coeff2.k = 1.5, coeff1.meanlog = -0.5, coeff1.sdlog = 0.5)

# Compare density with the Right-Pareto Lognormal distribution
plot(x = seq(0, 5, length.out = 1e3), y = dcomposite(x = seq(0, 5, length.out = 1e3),
dist = dist, coeff = coeff))
lines(x = seq(0, 5, length.out = 1e3), y = drightparetolognormal(x = seq(0, 5, length.out = 1e3)))

# Demonstration of log functionality for probability and quantile function
qcomposite(pcomposite(2, dist = dist, coeff = coeff, log.p = TRUE), dist = dist,
coeff = coeff, log.p = TRUE)

# The zeroth truncated moment is equivalent to the probability function
pcomposite(2, dist = dist, coeff = coeff)
mcomposite(truncation = 2, dist = dist, coeff = coeff)

# The (truncated) first moment is equivalent to the mean of a (truncated) random sample,
#for large enough samples.
coeff <- c(coeff1.meanlog = -0.5, coeff1.sdlog = 0.5, coeff2.k = 3)
x <- rcomposite(1e5, dist = dist, coeff = coeff)

mean(x)
mcomposite(r = 1, lower.tail = FALSE, dist = dist, coeff = coeff)

sum(x[x > quantile(x, 0.1)]) / length(x)
mcomposite(r = 1, truncation = quantile(x, 0.1), lower.tail = FALSE, dist = dist, coeff = coeff)

[Package distributionsrd version 0.0.6 Index]