[Stable]

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.

dist_gamma(shape, rate, scale = 1/rate)

Arguments

shape, scale

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

rate

an alternative way to specify the scale.

Details

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] 0.5970121 2.1354175 2.3394327 2.6698379 4.2151967 0.2848691 3.6185362
#>  [8] 1.5453918 0.1147746 2.5311914
#> 
#> [[2]]
#>  [1] 4.8585414 2.2834344 2.2341124 7.1694873 2.4781261 3.7554989 3.5044898
#>  [8] 0.7761629 3.4302730 3.2860253
#> 
#> [[3]]
#>  [1] 2.799240 9.273086 1.849671 8.824569 3.678787 4.392324 3.678566 5.255045
#>  [9] 1.811562 6.233091
#> 
#> [[4]]
#>  [1] 7.903940 2.848568 5.742856 5.741595 3.209648 5.791430 3.418631 2.993352
#>  [9] 5.370028 6.626941
#> 
#> [[5]]
#>  [1] 6.182160 6.144351 2.836682 5.191913 3.397029 6.309035 3.886205 4.128682
#>  [9] 2.841210 3.940077
#> 
#> [[6]]
#>  [1]  7.619538  8.741852  7.307199 11.535473  5.563535  4.705383 10.584592
#>  [8]  5.880328  5.030041  3.931025
#> 
#> [[7]]
#>  [1] 2.127542e+00 2.659347e-03 2.335614e-05 3.193039e-02 8.049553e-02
#>  [6] 8.194673e-02 6.960383e-01 1.980371e-01 5.638293e-02 1.078596e-02
#> 

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