##' Calculate shape and rate for gamma distribution from mean, mode and standard deviation.
##'
##'
##'
##' @export
gamma_mean <- function(mean , sd) {
if ( mean <=0 ) stop("mean must be > 0")
if ( sd <=0 ) stop("sd must be > 0")
shape = mean^2/sd^2
rate = mean/sd^2
return( list( shape=shape , rate=rate ) )
}
gamma_mode <- function( mode , sd ) {
if ( mode <=0 ) stop("mode must be > 0")
if ( sd <=0 ) stop("sd must be > 0")
rate = ( mode + sqrt( mode^2 + 4 * sd^2 ) ) / ( 2 * sd^2 )
shape = 1 + mode * rate
return( list( shape=shape , rate=rate ) )
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.