gammaGetShapeRate: Convert gamma mean and dispersion parameters to shape and...

Description Usage Arguments Details Value Examples

View source: R/gammaGetShapeRate.R

Description

Convert gamma mean and dispersion parameters to shape and rate parameters

Usage

1
gammaGetShapeRate(mean, dispersion)

Arguments

mean

The mean of a gamma distribution

dispersion

The dispersion parameter of a gamma distribution

Details

In simstudy, users specify the gamma distribution as a function of two parameters - a mean and dispersion. In this case, the variance of the specified distribution is (mean^2)*dispersion. The base R function rgamma uses the shape and rate parameters to specify the gamma distribution. This function converts the mean and dispersion into the shape and rate.

Value

A list that includes the shape and rate parameters of the gamma distribution

Examples

1
2
3
4
5
6
7
8
set.seed(12345)
mean = 5; dispersion = 1.5
rs <- gammaGetShapeRate(mean, dispersion)
c(rs$shape, rs$rate)
vec <- rgamma(1000, shape = rs$shape, rate = rs$rate)
(estMoments <- c(mean(vec), var(vec)))
(theoryMoments <- c(mean, mean^2*dispersion))
(theoryMoments <- c(rs$shape/rs$rate, rs$shape/rs$rate^2))

kgoldfeld/simstudy documentation built on Nov. 8, 2018, 7:41 p.m.