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 = 1/scale, scale = 1/rate)We recommend reading this documentation on pkgdown which renders math nicely. https://pkg.mitchelloharawild.com/distributional/reference/dist_gamma.html
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 $$
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.11581299 0.01207246 1.58898108 3.90423017 0.14966641 1.92948102
#> [7] 1.92844748 0.28476430 1.96941941 0.37799871
#>
#> [[2]]
#> [1] 1.3896288 4.0370983 5.6294157 6.6653570 6.5869498 0.9553802 4.6919852
#> [8] 1.6774169 6.9300763 2.4075783
#>
#> [[3]]
#> [1] 4.738433 2.202673 4.338423 5.751059 7.159705 5.369828 10.874383
#> [8] 3.349401 2.440180 9.581556
#>
#> [[4]]
#> [1] 3.611930 2.952707 2.126494 8.656802 3.237723 8.747899 4.521361 8.021796
#> [9] 5.086454 5.397582
#>
#> [[5]]
#> [1] 3.107934 3.290115 3.578270 3.114171 3.035854 3.375519 5.765367 4.046219
#> [9] 3.046654 3.874765
#>
#> [[6]]
#> [1] 5.675854 11.695185 6.013864 7.958027 11.307091 9.173052 10.429745
#> [8] 6.642370 11.189164 8.225343
#>
#> [[7]]
#> [1] 4.508443e-01 8.087757e-01 7.064181e-01 6.658913e-04 4.900713e-03
#> [6] 2.980295e-01 1.286290e-06 2.498401e-02 4.117234e-02 6.374258e-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