Learn R Programming

evmix (version 2.12)

mgamma: Mixture of Gammas Distribution

Description

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.

Usage

dmgamma(x, mgshape = 1, mgscale = 1, mgweight = NULL, log = FALSE)

pmgamma(q, mgshape = 1, mgscale = 1, mgweight = NULL, lower.tail = TRUE)

qmgamma(p, mgshape = 1, mgscale = 1, mgweight = NULL, lower.tail = TRUE)

rmgamma(n = 1, mgshape = 1, mgscale = 1, mgweight = NULL)

Arguments

x

quantiles

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)

Value

dmgamma gives the density, pmgamma gives the cumulative distribution function, qmgamma gives the quantile function and rmgamma gives a random sample.

Acknowledgments

Thanks to Daniela Laas, University of St Gallen, Switzerland for reporting various bugs in these functions.

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 (\(\alpha\)):

  • \(f(0+)=\infty\) for \(0<\alpha<1\);

  • \(f(0+)=1/\beta\) for \(\alpha=1\) (exponential);

  • \(f(0+)=0\) for \(\alpha>1\);

where \(\beta\) is the scale parameter.

References

http://www.math.canterbury.ac.nz/~c.scarrott/evmix

http://en.wikipedia.org/wiki/Gamma_distribution

http://en.wikipedia.org/wiki/Mixture_model

McLachlan, G.J. and Peel, D. (2000). Finite Mixture Models. Wiley.

See Also

gammagpd, gpd and dgamma

Other mgamma: fmgammagpdcon, fmgammagpd, fmgamma, mgammagpdcon, mgammagpd

Other mgammagpd: fgammagpd, fmgammagpdcon, fmgammagpd, fmgamma, gammagpd, mgammagpdcon, mgammagpd

Other mgammagpdcon: fgammagpdcon, fmgammagpdcon, fmgammagpd, fmgamma, gammagpdcon, mgammagpdcon, mgammagpd

Other fmgamma: fmgamma

Examples

Run this code
# NOT RUN {
set.seed(1)
par(mfrow = c(2, 1))

n = 1000
x = rmgamma(n, mgshape = c(1, 6), mgscale = c(1,2), mgweight = c(1, 2))
xx = seq(-1, 40, 0.01)

hist(x, breaks = 100, freq = FALSE, xlim = c(-1, 40))
lines(xx, dmgamma(xx, mgshape = c(1, 6), mgscale = c(1, 2), mgweight = c(1, 2)))

# By direct simulation
n1 = rbinom(1, n, 1/3) # sample size from population 1
x = c(rgamma(n1, shape = 1, scale = 1), rgamma(n - n1, shape = 6, scale = 2))

hist(x, breaks = 100, freq = FALSE, xlim = c(-1, 40))
lines(xx, dmgamma(xx, mgshape = c(1, 6), mgscale = c(1, 2), mgweight = c(1, 2)))
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab