Distributions Guide

This section provides detailed information about all probability distributions available in greybox.

Overview

greybox provides a comprehensive set of probability distributions for modeling different types of data. Each distribution family includes:

  • Density function (d*) - Probability density function (PDF)

  • Cumulative distribution function (p*) - CDF

  • Quantile function (q*) - Inverse CDF

  • Random generator (r*) - Random sample generation

Common Parameters

Most distribution functions share common parameters:

  • q or x : Value(s) at which to evaluate the function

  • loc or mu : Location parameter (often the mean)

  • scale : Scale parameter (often the standard deviation)

  • shape : Shape parameter(s) specific to the distribution

  • log / log_p : If True, return the log of the probability

  • lower_tail : If True (default), probabilities are P[X <= x]

Continuous Univariate Distributions

Normal (Gaussian)

dnorm(q, mean=0, sd=1, log=False)

Normal (Gaussian) distribution density.

Parameters:
  • q – Value(s) at which to evaluate

  • mean – Mean (location parameter)

  • sd – Standard deviation (scale parameter)

  • log – If True, return log density

Returns:

Density at q

Example:

from greybox import dnorm
dnorm(0, mean=0, sd=1)  # ~0.3989

Laplace

dlaplace(q, loc=0, scale=1, log=False)

Laplace (double exponential) distribution density.

Parameters:
  • q – Value(s) at which to evaluate

  • loc – Location parameter (median)

  • scale – Scale parameter

  • log – If True, return log density

Returns:

Density at q

S Distribution

ds(q, mu=0, scale=1, log=False)

S-distribution density - a heavy-tailed distribution.

Parameters:
  • q – Value(s) at which to evaluate

  • mu – Location parameter

  • scale – Scale parameter

  • log – If True, return log density

Returns:

Density at q

Generalized Normal

dgnorm(q, mu=0, scale=1, shape=1, log=False)

Generalized Normal distribution density.

Parameters:
  • q – Value(s) at which to evaluate

  • mu – Location parameter

  • scale – Scale parameter

  • shape – Shape parameter (controls tail weight) - shape=1: Laplace - shape=2: Normal - shape<2: Heavy tails - shape>2: Light tails

  • log – If True, return log density

Returns:

Density at q

Example:

from greybox import dgnorm
# Normal-like
dgnorm(0, mu=0, scale=1, shape=2)
# Heavy-tailed
dgnorm(5, mu=0, scale=1, shape=1)

Logistic

dlogis(q, loc=0, scale=1, log=False)

Logistic distribution density.

Parameters:
  • q – Value(s) at which to evaluate

  • loc – Location parameter

  • scale – Scale parameter

  • log – If True, return log density

Returns:

Density at q

Student’s t

dt(q, df, loc=0, scale=1, log=False)

Student’s t distribution density.

Parameters:
  • q – Value(s) at which to evaluate

  • df – Degrees of freedom

  • loc – Location parameter

  • scale – Scale parameter

  • log – If True, return log density

Returns:

Density at q

Asymmetric Laplace

dalaplace(q, mu=0, scale=1, alpha=0.5, log=False)

Asymmetric Laplace distribution density for quantile regression.

Parameters:
  • q – Value(s) at which to evaluate

  • mu – Location parameter

  • scale – Scale parameter

  • alpha – Asymmetry parameter (0 < alpha < 1) - alpha < 0.5: Right-skewed - alpha > 0.5: Left-skewed

  • log – If True, return log density

Returns:

Density at q

Log-Transformed Distributions

These distributions model the log of the response variable.

Log-Normal

dlnorm(q, meanlog=0, sdlog=1, log=False)

Log-Normal distribution density.

Parameters:
  • q – Value(s) - must be positive

  • meanlog – Mean of the underlying normal distribution

  • sdlog – Standard deviation of the underlying normal distribution

  • log – If True, return log density

Returns:

Density at q

Note: For positive-valued data that is right-skewed.

Log-Laplace

dllaplace(q, loc=0, scale=1, log=False)

Log-Laplace distribution density.

Parameters:
  • q – Value(s) - must be positive

  • loc – Location parameter (of log values)

  • scale – Scale parameter

  • log – If True, return log density

Returns:

Density at q

Log-S

dls(q, loc=0, scale=1, log=False)

Log-S distribution density.

Parameters:
  • q – Value(s) - must be positive

  • loc – Location parameter (of log values)

  • scale – Scale parameter

  • log – If True, return log density

Returns:

Density at q

Log-Generalized Normal

dlgnorm(q, mu=0, scale=1, shape=2, log=False)

Log-Generalized Normal distribution density.

Parameters:
  • q – Value(s) - must be positive

  • mu – Location parameter (of log values)

  • scale – Scale parameter

  • shape – Shape parameter

  • log – If True, return log density

Returns:

Density at q

Box-Cox Normal

dbcnorm(q, mu=0, sigma=1, lambda_bc=0, log=False)

Box-Cox Normal distribution density.

Parameters:
  • q – Value(s) - must be positive

  • mu – Location parameter

  • sigma – Scale parameter

  • lambda_bc – Box-Cox transformation parameter

  • log – If True, return log density

Returns:

Density at q

Folded and Rectified Distributions

These distributions model positive-valued data with a point mass at zero.

Folded Normal

dfnorm(q, mu=0, sigma=1, log=False)

Folded Normal distribution density.

Parameters:
  • q – Value(s) - must be non-negative

  • mu – Mean of underlying normal

  • sigma – Standard deviation of underlying normal

  • log – If True, return log density

Returns:

Density at q

Rectified Normal

drectnorm(q, mu=0, sigma=1, log=False)

Rectified Normal distribution density.

Parameters:
  • q – Value(s) - must be non-negative

  • mu – Mean of underlying normal

  • sigma – Standard deviation of underlying normal

  • log – If True, return log density

Returns:

Density at q

Distributions for Positive Values

Inverse Gaussian

dinvgauss(q, mu=1, scale=1, log=False)

Inverse Gaussian distribution density.

Parameters:
  • q – Value(s) - must be positive

  • mu – Mean parameter

  • scale – Scale parameter

  • log – If True, return log density

Returns:

Density at q

Gamma

dgamma(q, shape=1, scale=1, log=False)

Gamma distribution density.

Parameters:
  • q – Value(s) - must be positive

  • shape – Shape parameter (often denoted alpha)

  • scale – Scale parameter (often denoted theta)

  • log – If True, return log density

Returns:

Density at q

Exponential

dexp(q, loc=0, scale=1, log=False)

Exponential distribution density.

Parameters:
  • q – Value(s) - must be non-negative

  • loc – Location parameter

  • scale – Scale parameter (1/rate)

  • log – If True, return log density

Returns:

Density at q

Chi-Squared

dchi2(q, df, log=False)

Chi-squared distribution density.

Parameters:
  • q – Value(s) - must be non-negative

  • df – Degrees of freedom

  • log – If True, return log density

Returns:

Density at q

Count Distributions

Poisson

dpois(q, mu, log=False)

Poisson distribution probability mass function.

Parameters:
  • q – Value(s) - must be non-negative integers

  • mu – Mean/lambda parameter

  • log – If True, return log probability

Returns:

Probability mass at q

Negative Binomial

dnbinom(q, mu=1, size=1, log=False)

Negative Binomial distribution probability mass function.

Parameters:
  • q – Value(s) - must be non-negative integers

  • mu – Mean parameter

  • size – Dispersion parameter

  • log – If True, return log probability

Returns:

Probability mass at q

Geometric

dgeom(q, prob, log=False)

Geometric distribution probability mass function.

Parameters:
  • q – Value(s) - must be non-negative integers

  • prob – Probability of success

  • log – If True, return log probability

Returns:

Probability mass at q

Binary/Bounded Distributions

Binomial

dbinom(q, size, prob, log=False)

Binomial distribution probability mass function.

Parameters:
  • q – Value(s) - must be integers between 0 and size

  • size – Number of trials

  • prob – Probability of success

  • log – If True, return log probability

Returns:

Probability mass at q

Beta

dbeta(q, a, b, log=False)

Beta distribution density.

Parameters:
  • q – Value(s) - must be in [0, 1]

  • a – First shape parameter (alpha)

  • b – Second shape parameter (beta)

  • log – If True, return log density

Returns:

Density at q

Logit-Normal

dlogitnorm(q, mu=0, sigma=1, log=False)

Logit-Normal distribution density.

Parameters:
  • q – Value(s) - must be in (0, 1)

  • mu – Mean of underlying normal (logit scale)

  • sigma – Standard deviation (logit scale)

  • log – If True, return log density

Returns:

Density at q

CDF-Based Distributions

These distributions use the CDF in the likelihood.

Logistic CDF

plogis(q, location=0, scale=1, log_p=False, lower_tail=True)

Logistic cumulative distribution function.

Probit (Normal CDF)

pnorm(q, loc=0, scale=1, log_p=False, lower_tail=True)

Normal cumulative distribution function.

Summary

greybox supports the following distributions. For each distribution family, use the appropriate prefix:

  • d* - Probability density/mass function (PDF/PMF)

  • p* - Cumulative distribution function (CDF)

  • q* - Quantile function (inverse CDF)

  • r* - Random number generation

The choice of distribution depends on the nature of your data:

  • Continuous, symmetric: Normal, Laplace, Logistic, Student’s t

  • Heavy tails: Laplace, S, Generalized Normal, Student’s t

  • Positive, right-skewed: Log-Normal, Gamma, Inverse Gaussian

  • Count data: Poisson, Negative Binomial, Geometric

  • Proportions: Beta, Logit-Normal, Binomial

  • Zero-inflated: Folded Normal, Rectified Normal