Distributions

yli.beta_oddsratio = <yli.distributions.betaoddsrat_gen object>

Ratio of the odds of 2 independent beta-distributed variables

This is a SciPy stats.rv_continuous distribution which takes 4 parameters, a1, b1, a2 and b2, and gives the distribution of (X/(1-X)) / (Y/(1-Y)), where X ~ Beta(a1, b1), and Y ~ Beta(a2, b2).

Reference: Hora SC, Kelley GD. Bayesian inference on the odds and risk ratios. Communications in Statistics: Theory and Methods. 1983;12(6):725–38. doi: 10.1080/03610928308828491

betaoddsrat_gen.from_scipy(beta1, beta2)

Construct a new beta_oddsratio distribution from two SciPy beta distributions

Parameters:
  • beta1 (frozen SciPy stats.beta) – Distribution for the numerator of the ratio

  • beta2 (frozen SciPy stats.beta) – Distribution for the denominator of the ratio

Return type:

Frozen beta_oddsratio distribution

betaoddsrat_gen.set_cdf_terms(cdf_terms)

Set the number of terms to use when calculating the CDF

If cdf_terms = np.inf (default), the CDF will be computed by numerical integration of the PDF.

Otherwise, the CDF will be computed by truncating the infinite sum given by Hora & Kelley to the specified number of terms.

yli.beta_ratio = <yli.distributions.betarat_gen object>

Ratio of 2 independent beta-distributed variables

This is a SciPy stats.rv_continuous distribution which takes 4 parameters, a1, b1, a2 and b2, and gives the distribution of Beta(a1, b1) / Beta(a2, b2).

References:

  1. Pham-Gia T. Distributions of the ratios of independent beta variables and applications. Communications in Statistics: Theory and Methods. 2000;29(12):2693–715. doi: 10.1080/03610920008832632

  2. Weekend Editor. On the ratio of Beta-distributed random variables. Some Weekend Reading. 2021 Sep 13. https://www.someweekendreading.blog/beta-ratios/

betarat_gen.from_scipy(beta1, beta2)

Construct a new beta_ratio distribution from two SciPy beta distributions

Parameters:
  • beta1 (frozen SciPy stats.beta) – Distribution for the numerator of the ratio

  • beta2 (frozen SciPy stats.beta) – Distribution for the denominator of the ratio

Return type:

Frozen beta_ratio distribution

yli.transformed_dist = <yli.distributions.transformed_gen object>

Represents a transformation, Y, of a “base” random variable, X

This is a SciPy stats.rv_continuous distribution which takes parameters as described below.

The transformation is f(Y) = X. Hence Y.pdf(x) = X.pdf(f(x)) * f’(x).

For example, if X is a model parameter, then transformed_dist(X, f=np.exp, fprime=np.exp, finv=np.log) is the distribution of the log-parameter.

Parameters:

  • base (frozen SciPy distribution) – Distribution of the base random variable

  • f (callable) – Function f representing the transformation, which takes values of Y to values of X

  • fprime (callable) – Derivative of the function f

  • finv (callable) – Inverse of the function f, which takes values of X to values of Y

yli.hdi(distribution, level=None)

Get the highest density interval for the distribution, e.g. for a Bayesian posterior, the highest posterior density interval (HPD/HDI)

Parameters:
  • distribution (frozen SciPy distribution) – Distribution to compute the interval for

  • level (float) – Coverage/confidence probability, default (None) is 1 − config.alpha

Return type:

yli.utils.Interval