Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Distribution Gallery: Add Gamma #506

Merged
merged 2 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 98 additions & 0 deletions docs/examples/gallery/gamma.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
---
jupytext:
text_representation:
extension: .md
format_name: myst
kernelspec:
display_name: Python 3
language: python
name: python3
---
# Gamma Distribution

The gamma distribution is a continuous probability distribution that describes the time until a specified number of events occur in a Poisson process, in which $\alpha$ events occur continuously and independently at a constant average rate $\beta$. The gamma distribution is characterized by two parameters: the shape parameter $\alpha$ and the rate parameter $\beta$.

The gamma distribution is widely used in many settings, including modeling the time until a specified number of decays of a radioactive atom, the time until a specified number of seizures in patients with epilepsy, the time until a specified number of failures of a machine, and the time until a specified number of changes in the price of a stock.

The gamma distribution is used as a conjugate prior for the exponential distribution and for the precision of the normal distribution. It can also used as prior for scale parameters, in particular when there is interest in avoiding values close to zero or one wants to include more information than with other prior commonly used for scale parameter like the halfnormal or the exponential.

## Probability Density Function (PDF):

```{code-cell}
---
tags: [remove-input]
mystnb:
image:
alt: Gamma Distribution PDF
---

import arviz as az
from preliz import Gamma
az.style.use('arviz-doc')
alphas = [1, 3, 7.5]
betas = [0.5, 1., 1.]

for alpha, beta in zip(alphas, betas):
Gamma(alpha, beta).plot_pdf()
```

## Cumulative Distribution Function (CDF):

```{code-cell}
---
tags: [remove-input]
mystnb:
image:
alt: Gamma Distribution CDF
---

for alpha, beta in zip(alphas, betas):
Gamma(alpha, beta).plot_cdf()
```

## Key properties and parameters:

```{eval-rst}

======== ==========================================
Support :math:`x \in (0, \infty)`
Mean :math:`\frac{\alpha}{\beta}`
Variance :math:`\frac{\alpha}{\beta^2}`
======== ==========================================
```

**Probability Density Function (PDF):**

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

where $\Gamma$ is the [gamma function](https://en.wikipedia.org/wiki/Gamma_function).

**Cumulative Distribution Function (CDF):**

$$
F(x|\alpha, \beta) = \frac{1}{\Gamma(\alpha)} \gamma(\alpha, \beta x)
$$

where $\gamma$ is the [lower incomplete gamma function](https://en.wikipedia.org/wiki/Incomplete_gamma_function).

```{seealso}
:class: seealso

**Common Alternatives:**

- [Exponential Distribution](exponential.md) - A special case of the Gamma distribution with the shape parameter $\alpha = 1$.
- [Chi-Squared Distribution](chisquared.md) - A special case of the Gamma distribution with the shape parameter $\alpha = \nu/2$ and the scale parameter $\beta = 1/2$.

**Related Distributions:**

- [Inverse Gamma Distribution](inverse-gamma.md) - The reciprocal of a gamma-distributed random variable.
- [Poisson Distribution](poisson.md) - While the Gamma distribution models the time until a specified number of events occur in a Poisson process, the Poisson distribution models the number of events in fixed intervals of time or space.
- [Negative Binomial Distribution](negative-binomial.md) - The discrete counterpart of the Gamma distribution, modeling the number of trials needed to achieve a specified number of successes in a sequence of Bernoulli trials.
```


## References

- [Wikipedia - Gamma distribution](https://en.wikipedia.org/wiki/Gamma_distribution)
2 changes: 1 addition & 1 deletion docs/gallery_content.rst
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Continuous Distributions
Exponential

.. grid-item-card::
:link: ./api_reference.html#preliz.distributions.gamma.Gamma
:link: ./examples/gallery/gamma.html
:text-align: center
:shadow: none
:class-card: example-gallery
Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
``````````````A tool-box for prior elicitation
A tool-box for prior elicitation
===================================================

|PyPI version|
Expand Down