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$$

## 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] 4.7646301 0.4405824 0.1415912 6.6723421 2.1960107 1.0278619 1.1543096
#>  [8] 0.1801772 2.5428073 1.4913573
#>
#> [[2]]
#>  [1] 6.626560 3.759472 4.050416 6.196895 2.321857 2.621800 4.187313 2.724921
#>  [9] 5.560298 9.217549
#>
#> [[3]]
#>  [1] 12.574321  3.709150  6.248444  1.083010 18.318534  8.171705  6.602948
#>  [8]  3.417184  1.797502  5.296013
#>
#> [[4]]
#>  [1] 6.591793 4.298311 3.384493 3.067961 3.361640 2.140615 4.194592 8.623396
#>  [9] 6.097418 6.937068
#>
#> [[5]]
#>  [1] 4.548715 5.105341 3.973302 7.782889 2.186604 2.968325 3.654989 4.109330
#>  [9] 2.888640 2.389665
#>
#> [[6]]
#>  [1] 4.833977 3.918836 8.554214 8.765721 7.065512 6.513482 7.414076 9.938839
#>  [9] 6.276112 8.374170
#>
#> [[7]]
#>  [1] 6.871507e-02 9.873832e-01 1.149153e-01 3.508432e-01 2.377104e-05
#>  [6] 7.506791e-01 3.017052e-01 8.269260e-01 2.002100e+00 1.768326e-01
#>

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