Gamma distribution parameters from mean and variance of data distribution
set.seed(31234) x <- rgamma(100, shape=2.0, rate=11.0) hist(x) #print(x) shape <- 2.0 rate <- 11.0 scale <- 1/rate m <- mean(x) print(shape * scale) print(shape * 1 / rate) v <- var(x) print(shape * scale^2) print(shape * (1 / rate) ^2) print(m) print(v) scale <- v/m shape <- m*m/v rate <- 1/scale print(shape) print(rate) library(fitdistrplus) fitdist(data=x, distr="gamma", method = "mle") fitdist(data=x, distr="gamma", method = "mme") Note that the gamma distribution cannot be fitted when standard deviation (and then variance) is null: scale <- v/m # is 0 shape <- m*m/v # is +Inf rate <- 1/scale # is +Inf And > x <- rep(100, 1000) > library(fitdistrplus) > fitdist(data=x, distr="gamma", method = "mle") <simpleError in optim(par = vstart, fn = fnobj, fix.arg = fix.arg, obs = data, gr = gradient, ddistnam = ddistname, hessian = TRUE...