From 621f14ed0588d91ad4c1a5f86603ab5bebf9df39 Mon Sep 17 00:00:00 2001 From: aleicazatti Date: Wed, 6 Nov 2024 22:19:05 -0300 Subject: [PATCH 1/2] Distributions Gallery: Add BetaBinomial --- docs/examples/gallery/betabinomial.md | 97 +++++++++++++++++++++++++++ docs/gallery_content.rst | 2 +- 2 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 docs/examples/gallery/betabinomial.md diff --git a/docs/examples/gallery/betabinomial.md b/docs/examples/gallery/betabinomial.md new file mode 100644 index 0000000..995a5c1 --- /dev/null +++ b/docs/examples/gallery/betabinomial.md @@ -0,0 +1,97 @@ +--- +jupytext: + text_representation: + extension: .md + format_name: myst +kernelspec: + display_name: Python 3 + language: python + name: python3 +--- +# Beta-Binomial Distribution + + + +The Beta-Binomial distribution is a discrete probability distribution derived from the Binomial distribution, with its probability of success in each trial governed by a Beta distribution. This distribution is characterized by three parameters: $\alpha$, $\beta$, and $n$, where $\alpha$ and $\beta$ are the shape parameters of the Beta distribution and $n$ is the number of trials in the Binomial distribution. + +In Bayesian statistics, the Beta-Binomial distribution is commonly used as a prior for the probability of success in a Bernoulli trial. This makes it particularly useful in modeling scenarios with uncertainty in the success probability. + + +## Probability Mass Function (PMF): + +```{code-cell} +--- +tags: [remove-input] +mystnb: + image: + alt: Beta-Binomial Distribution PMF +--- + +from preliz import BetaBinomial, style +style.use('preliz-doc') +alphas = [0.5, 1, 2.3] +betas = [0.5, 1, 2] +n = 10 +for a, b in zip(alphas, betas): + BetaBinomial(a, b, n).plot_pdf() +``` + +## Cumulative Distribution Function (CDF): + +```{code-cell} +--- +tags: [remove-input] +mystnb: + image: + alt: Beta-Binomial Distribution CDF +--- + +for a, b in zip(alphas, betas): + BetaBinomial(a, b, n).plot_cdf() +``` + +## Key properties and parameters: + +```{eval-rst} +======== ================================================================= +Support :math:`x \in \{0, 1, \ldots, n\}` +Mean :math:`n \dfrac{\alpha}{\alpha + \beta}` +Variance :math:`\dfrac{n \alpha \beta (\alpha+\beta+n)}{(\alpha+\beta)^2 (\alpha+\beta+1)}` +======== ================================================================= +``` + +**Probability Mass Function (PMF):** + +$$ +f(x \mid \alpha, \beta, n) = \binom{n}{x} \frac{B(x + \alpha, n - x + \beta)}{B(\alpha, \beta)} +$$ + +where $B$ is the [Beta function](https://en.wikipedia.org/wiki/Beta_function) and $\binom{n}{x}$ is the [binomial coefficient](https://en.wikipedia.org/wiki/Binomial_coefficient). + +**Cumulative Distribution Function (CDF):** + +$$ +F(x \mid \alpha, \beta, n) = +\begin{cases} +0, & x < 0 \\ +\sum_{k=0}^{x} \binom{n}{k} \frac{B(k + \alpha, n - k + \beta)}{B(\alpha, \beta)}, & 0 \leq x < n \\ +1, & x \geq n +\end{cases} +$$ + +```{seealso} +:class: seealso + +**Related Distributions:** + +- [Binomial](binomial.md) - The Beta-Binomial distribution is a compound distribution derived from the Binomial distribution. +- [Beta](beta.md) - The Beta-Binomial distribution is a compound distribution parameterized by the Beta distribution. +``` + +## References + +- [Wikipedia - Beta-Binomial](https://en.wikipedia.org/wiki/Beta-binomial_distribution) + + + + diff --git a/docs/gallery_content.rst b/docs/gallery_content.rst index 5c77a6e..c8d3113 100644 --- a/docs/gallery_content.rst +++ b/docs/gallery_content.rst @@ -408,7 +408,7 @@ Discrete Distributions Bernoulli .. grid-item-card:: - :link: ./api_reference.html#preliz.distributions.betabinomial.BetaBinomial + :link: ./examples/gallery/betabinomial.html :text-align: center :shadow: none :class-card: example-gallery From 78514d8a9b5d59d752399c0b263ed79514efd566 Mon Sep 17 00:00:00 2001 From: Alejandro Icazatti Date: Thu, 7 Nov 2024 12:53:54 -0300 Subject: [PATCH 2/2] Apply suggestion Co-authored-by: Osvaldo A Martin --- docs/examples/gallery/betabinomial.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/examples/gallery/betabinomial.md b/docs/examples/gallery/betabinomial.md index 995a5c1..dd6f72e 100644 --- a/docs/examples/gallery/betabinomial.md +++ b/docs/examples/gallery/betabinomial.md @@ -14,7 +14,6 @@ kernelspec: The Beta-Binomial distribution is a discrete probability distribution derived from the Binomial distribution, with its probability of success in each trial governed by a Beta distribution. This distribution is characterized by three parameters: $\alpha$, $\beta$, and $n$, where $\alpha$ and $\beta$ are the shape parameters of the Beta distribution and $n$ is the number of trials in the Binomial distribution. -In Bayesian statistics, the Beta-Binomial distribution is commonly used as a prior for the probability of success in a Bernoulli trial. This makes it particularly useful in modeling scenarios with uncertainty in the success probability. ## Probability Mass Function (PMF):