composite function

The two- or three-composite distribution

The two- or three-composite distribution

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

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[Xx]P[X \leq x] (E[xrXy])(E[x^r|X \leq y]), otherwise, P[X>x]P[X > x] (E[xrX>y])(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

Returns

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.

Details

These derivations are based on the two-composite distribution proposed by if(!exists(".Rdpack.currefs")) .Rdpack.currefs <-new.env();Rdpack::insert_citeOnly(keys="bakar2015modelling",package="distributionsrd",cached_env=.Rdpack.currefs) . Probability Distribution Function:

f(x)={α11+α1+α2m1(x)M1(c1)if0<xc111+α1+α2m2(x)M2(c2)M2(c1)ifc1<xc2α21+α1+α2m3(x)1M3(c2)ifc2<x<. f(x) = \{ \begin{array}{lrl}\frac{\alpha_1}{1 + \alpha_1 + \alpha_2} \frac{m_1(x)}{M_1(c_1)} & { if} & 0<x \leq c_1 \\\frac{1}{1 + \alpha_1 + \alpha_2} \frac{m_2(x)}{M_2(c_2) - M_2(c_1)} & { if} & c_1<x \leq c_2 \\\frac{\alpha_2}{1 + \alpha_1 + \alpha_2} \frac{m_3(x)}{1-M_3(c_2)} & { if} & c_{2}<x < \infty \\\end{array} .

Cumulative Distribution Function:

{α11+α1+α2M1(x)M1(c1)if0<xc1α11+α1+α2+11+α1+α2M2(x)M2(c1)M2(c2)M2(c1)ifc1<xc21+α11+α1+α2+α21+α1+α2M3(x)M3(c2)1M3(c2)ifc2<x<. \{\begin{array}{lrl}\frac{\alpha_1}{1 + \alpha_1 + \alpha_2} \frac{M_1(x)}{M_1(c_1)} & { if} & 0<x \leq c_1 \\\frac{\alpha_1}{1 + \alpha_1 + \alpha_2} + \frac{1}{1 + \alpha_1 + \alpha_2}\frac{M_2(x) - M_2(c_1)}{M_2(c_2) - M_2(c_1)} & { if} & c_1<x \leq c_2 \\\frac{1+\alpha_1}{1 + \alpha_1 + \alpha_2} + \frac{\alpha_2}{1 + \alpha_1 + \alpha_2} \frac{M_3(x) - M_3(c_2)}{1-M_3(c_2)} & { if} & c_{2}<x < \infty \\\end{array}.

Quantile function

Q(p)={Q1(1+α1+α2α1pM1(c1))if0<xα11+α1+α2Q2[((pα11+α1+α2)(1+α1+α2)(M2(c2)M2(c1)))+M2(c1)]ifα11+α1+α2<x1+α11+α1+α2Q3[((p1+α11+α1+α2)(1+α1+α2α2)(1M3(c2)))+M3(c2)]if1+α11+α1+α2<x<. Q(p) = \{\begin{array}{lrl}Q_1( \frac{1 + \alpha_1 + \alpha_2}{\alpha_1} p M_1(c_1) ) & { if} & 0<x \leq \frac{\alpha_1}{1 + \alpha_1 + \alpha_2} \\Q_2[((p - \frac{\alpha_1}{1 + \alpha_1 + \alpha_2})(1 + \alpha_1 + \alpha_2)(M_2(c_2) - M_2(c_1))) + M_2(c_1)] & { if} & \frac{\alpha_1}{1 + \alpha_1 + \alpha_2}<x \leq \frac{1+\alpha_1}{1 + \alpha_1 + \alpha_2} \\Q_3[((p - \frac{1+\alpha_1}{1 + \alpha_1 + \alpha_2})(\frac{1 + \alpha_1 + \alpha_2}{\alpha_2})(1 - M_3(c_2))) + M_3(c_2)] & { if} & \frac{1+\alpha_1}{1 + \alpha_1 + \alpha_2}<x < \infty \\\end{array}.

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

μyr={α11+α1+α2(μ1)yr(μ1)c1rM1(c1)+11+α1+α2(μ2)c1r(μ2)c2rM2(c2)M2(c1)+α21+α1+α2(μ3)yr1M3(c2)if0<yc211+α1+α2(μ2)yr(μ2)c2rM2(c2)M2(c1)+α21+α1+α2(μ3)c2r1M3(c2)ifc1<yc2α21+α1+α2(μ3)yr1M3(c2)ifc2<y<. \mu_y^r =\{\begin{array}{lrl}\frac{\alpha_1}{1 + \alpha_1 + \alpha_2}\frac{ (\mu_1)_y^r - (\mu_1)_{c_1}^r}{M_1(c_1)} + \frac{1}{1 + \alpha_1 + \alpha_2}\frac{ (\mu_2)_{c_1}^r - (\mu_2)_{c_2}^r }{M_2(c_2) - M_2(c_1)} + \frac{\alpha_2}{1 + \alpha_1 + \alpha_2} \frac{(\mu_3)_y^r}{1-M_3(c_2)} & { if} & 0< y \leq c_2 \\\frac{1}{1 + \alpha_1 + \alpha_2} \frac{(\mu_2)_y^r - (\mu_2)_{c_2}^r }{M_2(c_2) - M_2(c_1)} + \frac{\alpha_2}{1 + \alpha_1 + \alpha_2} \frac{(\mu_3)_{c_2}^r}{1-M_3(c_2)} & { if} & c_1< y \leq c_2\\\frac{\alpha_2}{1 + \alpha_1 + \alpha_2} \frac{(\mu_3)_y^r}{1-M_3(c_2)} & { if} & c_2< y < \infty \\\end{array}.

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)

References

if(!exists(".Rdpack.currefs")) .Rdpack.currefs <-new.env();Rdpack::insert_all_ref(.Rdpack.currefs)

  • Maintainer: Ruben Dewitte
  • License: GPL-3
  • Last published: 2020-05-25

Useful links