Density, cumulative distribution function, quantile function and random number generation for the mixture of gammas distribution. The parameters are the multiple gamma shapes mgshape scales mgscale and weights mgweights.
mgshape: mgamma shape (positive) as list or vector
mgscale: mgamma scale (positive) as list or vector
mgweight: mgamma weights (positive) as list or vector (NULL for equi-weighted)
log: logical, if TRUE then log density
q: quantiles
lower.tail: logical, if FALSE then upper tail probabilities
p: cumulative probabilities
n: sample size (positive integer)
Returns
dmgamma gives the density, pmgamma gives the cumulative distribution function, qmgamma gives the quantile function and rmgamma gives a random sample.
Details
Distribution functions for weighted mixture of gammas.
Suppose there are M>=1 gamma components in the mixture model. If you wish to have a single (scalar) value for each parameter within each of the M components then these can be input as a vector of length M. If you wish to input a vector of values for each parameter within each of the M components, then they are input as a list with each entry the parameter object for each component (which can either be a scalar or vector as usual). No matter whether they are input as a vector or list there must be M elements in mgshape and mgscale, one for each gamma mixture component. Further, any vectors in the list of parameters must of the same length of the x, q, p or equal to the sample size n, where relevant.
If mgweight=NULL then equal weights for each component are assumed. Otherwise, mgweight must be a list of the same length as mgshape and mgscale, filled with positive values. In the latter case, the weights are rescaled to sum to unity.
The gamma is defined on the non-negative reals. Though behaviour at zero depends on the shape (α):
f(0+)=∞ for 0\<α\<1;
f(0+)=1/β for α=1 (exponential);
f(0+)=0 for α1;
where β is the scale parameter.
Note
All inputs are vectorised except log and lower.tail, and the gamma mixture parameters can be vectorised within the list. The main inputs (x, p or q) and parameters must be either a scalar or a vector. If vectors are provided they must all be of the same length, and the function will be evaluated for each element of vector. In the case of rmgamma any input vector must be of length n. The only exception is when the parameters are single scalar values, input as vector of length M.
Default values are provided for all inputs, except for the fundamentals x, q and p. The default sample size for rmgamma is 1.
Missing (NA) and Not-a-Number (NaN) values in x, p and q are passed through as is and infinite values are set to NA. None of these are not permitted for the parameters.
Error checking of the inputs (e.g. invalid probabilities) is carried out and will either stop or give warning message as appropriate.
Acknowledgments
Thanks to Daniela Laas, University of St Gallen, Switzerland for reporting various bugs in these functions.