Stable lifecycle

dist_gamma(shape, rate)

Arguments

shape

shape and scale parameters. Must be positive, scale strictly.

rate

an alternative way to specify the scale.

Details

Several important distributions are special cases of the Gamma distribution. When the shape parameter is 1, the Gamma is an exponential distribution with parameter \(1/\beta\). When the \(shape = n/2\) and \(rate = 1/2\), the Gamma is a equivalent to a chi squared distribution with n degrees of freedom. Moreover, if we have \(X_1\) is \(Gamma(\alpha_1, \beta)\) and \(X_2\) is \(Gamma(\alpha_2, \beta)\), a function of these two variables of the form \(\frac{X_1}{X_1 + X_2}\) \(Beta(\alpha_1, \alpha_2)\). This last property frequently appears in another distributions, and it has extensively been used in multivariate methods. More about the Gamma distribution will be added soon.

We recommend reading this documentation on https://pkg.mitchelloharawild.com/distributional/, where the math will render nicely.

In the following, let \(X\) be a Gamma random variable with parameters shape = \(\alpha\) and rate = \(\beta\).

Support: \(x \in (0, \infty)\)

Mean: \(\frac{\alpha}{\beta}\)

Variance: \(\frac{\alpha}{\beta^2}\)

Probability density function (p.m.f):

$$ f(x) = \frac{\beta^{\alpha}}{\Gamma(\alpha)} x^{\alpha - 1} e^{-\beta x} $$

Cumulative distribution function (c.d.f):

$$ f(x) = \frac{\Gamma(\alpha, \beta x)}{\Gamma{\alpha}} $$

Moment generating function (m.g.f):

$$ E(e^{tX}) = \Big(\frac{\beta}{ \beta - t}\Big)^{\alpha}, \thinspace t < \beta $$

See also

Examples

dist <- dist_gamma(shape = c(1,2,3,5,9,7.5,0.5), rate = c(0.5,0.5,0.5,1,2,1,1)) dist
#> <distribution[7]> #> [1] Γ(1, 0.5) Γ(2, 0.5) Γ(3, 0.5) Γ(5, 1) Γ(9, 2) Γ(7.5, 1) Γ(0.5, 1)
mean(dist)
#> [1] 2.0 4.0 6.0 5.0 4.5 7.5 0.5
variance(dist)
#> [1] 4.00 8.00 12.00 5.00 2.25 7.50 0.50
skewness(dist)
#> [1] 2.0000000 1.4142136 1.1547005 0.8944272 0.6666667 0.7302967 2.8284271
kurtosis(dist)
#> [1] 6.0000000 3.0000000 2.0000000 1.2000000 0.6666667 0.8000000 12.0000000
generate(dist, 10)
#> [[1]] #> [1] 1.2512089 3.3559840 4.3208661 0.3609576 1.2831566 1.8291479 0.9416531 #> [8] 0.4366868 4.6013435 1.6077485 #> #> [[2]] #> [1] 2.6005049 0.7304135 3.4580268 4.3435227 0.6685505 1.0074184 4.7789035 #> [8] 2.0648440 4.0217902 1.1716659 #> #> [[3]] #> [1] 5.3751564 9.7834979 8.8321780 2.4042591 9.2821782 4.3250029 9.5021515 #> [8] 0.9654895 2.8517279 3.9495585 #> #> [[4]] #> [1] 3.329240 2.276877 5.962578 3.263537 5.616046 6.305447 8.266339 1.462075 #> [9] 3.350709 6.593450 #> #> [[5]] #> [1] 5.435235 5.252701 3.504752 5.411732 5.657428 6.698262 3.343114 7.146417 #> [9] 4.766021 2.996170 #> #> [[6]] #> [1] 3.765155 8.223336 8.878125 6.197700 6.140064 10.984905 6.421858 #> [8] 7.791447 7.533544 4.177806 #> #> [[7]] #> [1] 0.45128149 0.41699384 0.06357490 0.08025083 0.36764715 0.14933475 #> [7] 2.39695768 1.61768034 0.37536604 0.19726364 #>
density(dist, 2)
#> [1] 0.183939721 0.183939721 0.091969860 0.090223522 0.059540363 0.006545958 #> [7] 0.053990967
density(dist, 2, log = TRUE)
#> [1] -1.693147 -1.693147 -2.386294 -2.405465 -2.821101 -5.028908 -2.918939
cdf(dist, 4)
#> [1] 0.8646647 0.5939942 0.3233236 0.3711631 0.4074527 0.0762173 0.9953223
quantile(dist, 0.7)
#> [1] 2.4079456 4.8784330 7.2311353 5.8903613 5.1503385 8.6608472 0.5370971