dcoga {coga} R Documentation

## Convolution of Gamma Distributions (Exact Method).

### Description

Density, distribution function, and random generation for convolution of gamma distributions. Convolution of independent Gamma random variables is Y = X_{1} + ... + X_{n}, where X_{i}, i = 1, ..., n, are independent Gamma distributions with parameters shapes and rates. The exact density function and distribution function can be calculated, according to the formulas from Moschopoulos, Peter G. (1985). **We mention that dcoga and pcoga are recommended for n >= 3.**

### Usage

dcoga(x, shape, rate)

pcoga(x, shape, rate)

rcoga(n, shape, rate)


### Arguments

 x Quantiles. shape Numerical vector of shape parameters for each gamma distributions, all shape parameters should be larger than or equal to 0, with at least one non-zero. rate Numerical vector of rate parameters for each gamma distributions, all rate parameters should be larger than 0. n Number of sample points.

Chaoran Hu

### References

Moschopoulos, Peter G. "The distribution of the sum of independent gamma random variables." Annals of the Institute of Statistical Mathematics 37.1 (1985): 541-544.

### Examples

## Example 1: Correctness check
set.seed(123)
## do grid
y <- rcoga(100000, c(3,4,5), c(2,3,4))
grid <- seq(0, 15, length.out=100)
## calculate pdf and cdf
pdf <- dcoga(grid, shape=c(3,4,5), rate=c(2,3,4))
cdf <- pcoga(grid, shape=c(3,4,5), rate=c(2,3,4))

## plot pdf
plot(density(y), col="blue")
lines(grid, pdf, col="red")

## plot cdf
plot(ecdf(y), col="blue")
lines(grid, cdf, col="red")

## Example 2: Show parameter recycling
## these pairs give us the same results
dcoga(1:5, c(1, 2), c(1, 3, 4, 2, 5))
dcoga(1:5, c(1, 2, 1, 2, 1), c(1, 3, 4, 2, 5))

pcoga(1:5, c(1, 3, 5, 2, 2), c(3, 5))
pcoga(1:5, c(1, 3, 5, 2, 2), c(3, 5, 3, 5, 3))



[Package coga version 1.2.2 Index]