pymc.ZeroOneInflatedBeta#

class pymc.ZeroOneInflatedBeta(name, *args, rng=None, dims=None, initval=None, observed=None, total_size=None, transform=UNSET, default_transform=UNSET, **kwargs)[source]#

Zero-One-Inflated Beta Distribution.

The pdf of this distribution is:

\[\begin{split}f(x \mid \text{zoi}, \text{coi}, \alpha, \beta) = \begin{cases} \text{zoi} \cdot (1 - \text{coi}) & \text{if } x = 0 \\ \text{zoi} \cdot \text{coi} & \text{if } x = 1 \\ (1 - \text{zoi}) \cdot \dfrac{x^{\alpha - 1} (1 - x)^{\beta - 1}}{B(\alpha, \beta)} & \text{if } x \in (0, 1) \end{cases}\end{split}\]

where \(B\) is the Beta function, \(\alpha = \mu \kappa\), and \(\beta = (1 - \mu) \kappa\).

Parameters:
zoitensor_like of float

Probability of a structural value at 0 or 1, \(0 \leq zoi \leq 1\).

coitensor_like of float

Conditional probability given a structural value that it is a structural 1, \(0 \leq coi \leq 1\).

alphatensor_like of float, optional

alpha > 0. If not specified, then calculated using mu and kappa.

betatensor_like of float, optional

beta > 0. If not specified, then calculated using mu and kappa.

mutensor_like of float, optional

Mean of the Beta component, \(0 < \mu < 1\).

kappatensor_like of float, optional

Precision of the Beta component, \(\kappa > 0\).

Notes

ZeroOneInflatedBeta is appropriate for modeling proportion data when exact zeros or ones represent distinct processes (structural zeros and ones), separate from the tails of the Beta component.

References

[1]

Ospina, R., & Ferrari, S. L. (2010). Inflated beta distributions.

[2]

Ospina, R., & Ferrari, S. L. (2012). A general class of zero-or-one inflated beta regression models.

Examples

Model proportion data with structural zeros and ones:

import pymc as pm
import numpy as np

# Data with 30% boundary values, 40% of which are ones
true_zoi = 0.3
true_coi = 0.4
true_mu = 0.4
true_kappa = 20.0
n = 1000

rng = np.random.default_rng(100)
u = rng.random(n)
alpha = true_mu * true_kappa
beta  = (1 - true_mu) * true_kappa
beta_data = rng.beta(alpha, beta, n)
data = np.where(u < true_zoi * (1 - true_coi), 0.0,
       np.where(u < true_zoi, 1.0,
       beta_data))

# Fit model
with pm.Model() as model:
    zoi   = pm.Beta("zoi", alpha=1, beta=1)
    coi   = pm.Beta("coi", alpha=1, beta=1)
    mu    = pm.Beta("mu", alpha=2, beta=2)
    kappa = pm.Gamma("kappa", alpha=2, beta=0.1)
    y = pm.ZeroOneInflatedBeta(
        "y", zoi=zoi, coi=coi, mu=mu, kappa=kappa,
        observed=data
    )
    trace = pm.sample(1000, tune=1000)

Support

\(y \in [0, 1]\)

Mean

\((1 - \text{zoi})\mu + \text{zoi} \cdot \text{coi}\)

Variance

\((1-\text{zoi})\left[\dfrac{\mu(1-\mu)}{\kappa+1} + \text{zoi} \cdot \text{coi} \cdot (1 - \text{coi})\right] + \text{zoi}(1-\text{zoi})\mu^2\)

Setting \(coi = 0\) recovers the Zero-Inflated Beta (ZIB) distribution. Setting \(coi = 1\) recovers the One-Inflated Beta (OIB) distribution.

Methods

ZeroOneInflatedBeta.dist(zoi, coi[, mu, ...])

Create a tensor variable corresponding to the cls distribution.