I got two gamma distributions, which could be a good fit to my data, but to be sure I need to do Kolmogorov-Smirnov test as well as chi-square goodness of fit. (If you have any suggestion which other way is suitable to confirm that mixture distribution is suitable for my data, let me know).
I used gammamixEM from mixtools package in R to get parameters for those two gamma distributions. From the histogram it looks promising.
foo_CE <- gammamixEM(data_cexio$diff)
x1 <- seq(0, 70, 1)
hist(data_cexio$diff, freq= FALSE, col="grey",border="black")
lines(density(data_cexio$diff), lwd = 2, col = "blue")
lines(x1, foo_CE$lambda[1]*dgamma(x1, foo_CE$gamma.pars[1,1], 1/foo_CE$gamma.pars[2,1]),
col="orange", lwd=3)
lines(x1, foo_CE$lambda[2]*dgamma(x1, foo_CE$gamma.pars[1,2], 1/foo_CE$gamma.pars[2,2]),
col="magenta", lwd=3)
legend("topright", c("0.20 * Gamma ~ (1.70,0.24)","0.80 * Gamma ~ (6.40,0.22)" ), fill=c( "orange","magenta"))
Regarding Kolmogorov-Smirnov test I found in here: https://stats.stackexchange.com/questions/28873/goodness-of-fit-test-for-a-mixture-in-r and I modified for Gamma distribution:
# CDF of mixture of two gammas
CDF_gamma <- function(x, shape, scale, p) {
p[1]*pgamma(x,shape[1],1/scale[1]) + p[2]*pgamma(x,shape[2],1/scale[2])
}
test_CE <- ks.test(data_cexio$diff, CDF_gamma, shape=foo_CE$gamma.pars[1,], scale=foo_CE$gamma.pars[2,], p=foo_CE$lambda)
Unfortunately, p-value < 2.2e-16, so it is not a good fit according to this test. But I am not able to find how to perform chi-square goodness of fit as well to check if this mixture distribution would be good fit.