get_gamma_params: Get parameters of Gamma distribution

Description Usage Arguments Value Author(s) See Also Examples

View source: R/utils.R

Description

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.

Usage

1

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

Author(s)

John Giles

See Also

Other utility: get_admin_level(), get_beta_params(), get_pop_vec(), get_unique_coords(), get_unique_ids()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
mu <- 2
sigma <- 0.5

prm <- get_gamma_params(mu, sigma)

prm[1]/prm[2] # mean
sqrt(prm[1]/(prm[2]^2)) # sd

curve(dgamma(x, prm[1], prm[2]), 0, 5, xlab='Response variable', ylab='Density')
abline(v=mu, lty=2, col='red')

COVID-19-Mobility-Data-Network/mobility documentation built on Nov. 22, 2021, 12:17 a.m.