A function that finds the shape and rate parameters required by the Gamma distribution given the observed mean mu and standard deviation sigma of the response variable. Parameters are found numerically using a two-dimensional Nelder-Mead optimization algorithm.

get_gamma_params(mu, sigma)

Arguments

mu

the desired mean of the Gamma distribution

sigma

the desired standard deviation of the Gamma distribution

Value

a named numeric vector giving the shape and rate parameters of the Gamma distribution

See also

Author

John Giles

Examples

mu <- 2 sigma <- 0.5 prm <- get_gamma_params(mu, sigma) prm[1]/prm[2] # mean
#> shape #> 2
sqrt(prm[1]/(prm[2]^2)) # sd
#> shape #> 0.5
curve(dgamma(x, prm[1], prm[2]), 0, 5, xlab='Response variable', ylab='Density')
abline(v=mu, lty=2, col='red')