Sampling from a mixture of two Gamma distributions

251 views Asked by At

My intention was to generate samples from two mixed and heavily right-skewed Gamma distributions using the package called bmixture. Some examples are provided at https://stats.stackexchange.com/questions/226834/sampling-from-a-mixture-of-two-gamma-distributions. For example, I can use the following, although the distributions are not really skewed (instead they seems normal).

library(bmixture)
set.seed(345)
nn <- 10000
wt <- c(0.85,0.20) #weight2
mu <- c(20,70)
sd <- c(1,1.2)
x <- rmixgamma(n=nn,weight=wt,alpha=mu,beta=sd) 
hist(x, breaks = 40, freq=FALSE)

Output:

enter image description here

How can one possibly incorporate the skewness parameter? Any help is highly appreciated!

1

There are 1 answers

3
Allan Cameron On BEST ANSWER

You aren't using the parameters properly. alpha is the shape parameter, where lower values increase the skew (a shape of 1 gives the exponential distribution, and higher numbers tend towards a normal distribution), and beta is the rate parameter, where higher values lower the mean. (see Characterization using shape α and rate β here.)

The mean of a gamma distribution is alpha/beta, and the standard deviation is sqrt(alpha/beta^2). To get your target mean and standard deviations, you would need shape parameters of c(400, 3402) and rate parameters of c(20, 48.61). These shape parameters would lead to distributions that would be impossible to distinguish from normal distributions at reasonable sample sizes.

To get positively skewed distributions, you need considerably lower shape parameters:

library(bmixture)
set.seed(345)
nn <- 10000
wt <- c(0.80,0.20) 

shape <- c(3, 30)
rate <- shape / c(20, 70)

x <- rmixgamma(n = nn, weight = wt, alpha = shape, beta = rate) 

hist(x, breaks = 40, freq = FALSE)

Created on 2022-12-14 with reprex v2.0.2