[Maturing]

A mixture distribution combines multiple component distributions with specified weights. Two types of mixture are supported:

  • Probability mixture (type = "probability", the default): the CDF is a weighted average of the component CDFs. Also known as linear pooling.

  • Quantile mixture (type = "quantile"): the quantile function is a weighted average of the component quantile functions. Also known as Vincentization.

dist_mixture(..., weights = numeric(), type = c("probability", "quantile"))

Arguments

...

Distributions to be used in the mixture. Can be any distributional objects.

weights

A numeric vector of non-negative weights that sum to 1. The length must match the number of distributions passed to .... Each weight \(w_i\) represents the probability that a random draw comes from the \(i\)-th component distribution.

type

"probability" (default) for a probability mixture or "quantile" for a quantile mixture (Vincentization). Quantile mixtures only support univariate component distributions.

Details

In the following, let \(X\) be a mixture random variable composed of \(K\) component distributions \(F_1, F_2, \ldots, F_K\) with corresponding weights \(w_1, w_2, \ldots, w_K\) where \(\sum_{i=1}^K w_i = 1\) and \(w_i \geq 0\) for all \(i\).

Probability mixture (type = "probability")

Support: The union of the supports of all component distributions

Mean:

For univariate mixtures: $$ E(X) = \sum_{i=1}^K w_i \mu_i $$

where \(\mu_i\) is the mean of the \(i\)-th component distribution.

For multivariate mixtures: $$ E(\mathbf{X}) = \sum_{i=1}^K w_i \boldsymbol{\mu}_i $$

where \(\boldsymbol{\mu}_i\) is the mean vector of the \(i\)-th component distribution.

Variance:

For univariate mixtures: $$ \text{Var}(X) = \sum_{i=1}^K w_i (\mu_i^2 + \sigma_i^2) - \left(\sum_{i=1}^K w_i \mu_i\right)^2 $$

where \(\sigma_i^2\) is the variance of the \(i\)-th component distribution.

Covariance:

For multivariate mixtures: $$ \text{Cov}(\mathbf{X}) = \sum_{i=1}^K w_i \left[ (\boldsymbol{\mu}_i - \bar{\boldsymbol{\mu}})(\boldsymbol{\mu}_i - \bar{\boldsymbol{\mu}})^T + \boldsymbol{\Sigma}_i \right] $$

where \(\bar{\boldsymbol{\mu}} = \sum_{i=1}^K w_i \boldsymbol{\mu}_i\) is the overall mean vector and \(\boldsymbol{\Sigma}_i\) is the covariance matrix of the \(i\)-th component distribution.

Probability density/mass function (p.d.f/p.m.f):

$$ f(x) = \sum_{i=1}^K w_i f_i(x) $$

where \(f_i(x)\) is the density or mass function of the \(i\)-th component distribution.

Cumulative distribution function (c.d.f):

For univariate mixtures: $$ F(x) = \sum_{i=1}^K w_i F_i(x) $$

where \(F_i(x)\) is the c.d.f. of the \(i\)-th component distribution.

For multivariate mixtures, the c.d.f. is approximated numerically.

Quantile function:

For univariate probability mixtures, the quantile function has no closed form and is computed numerically by inverting the c.d.f. using root-finding (stats::uniroot()).

For multivariate mixtures, quantiles are not yet implemented.

Quantile mixture (type = "quantile")

Also known as a Vincent average or Vincentization, only univariate component distributions are supported.

Quantile function (closed form): $$ Q(p) = \sum_{i=1}^K w_i Q_i(p) $$

where \(Q_i(p)\) is the quantile function of the \(i\)-th component distribution.

Cumulative distribution function: computed numerically by inverting \(Q(p)\) via stats::uniroot().

Probability density function: derived analytically from the quantile function. For \(p = F(x)\): $$ f(x) = \frac{1}{Q'(p)} = \frac{1}{\sum_{i=1}^K w_i / f_i(Q_i(p))} $$

Mean: \(E(X) = \sum_{i=1}^K w_i \mu_i\) (identical to the probability mixture mean).

Variance: computed numerically as \(\int_0^1 Q(p)^2 \, dp - \left(E(X)\right)^2\).

Examples

# Probability mixture of two normal distributions (default)
dist <- dist_mixture(dist_normal(0, 1), dist_normal(5, 2), weights = c(0.3, 0.7))
dist
#> <distribution[1]>
#> [1] mixture(0.3*N(0, 1), 0.7*N(5, 4))

mean(dist)
#> [1] 3.5
variance(dist)
#> [1] 8.35

density(dist, 2)
#> [1] 0.06152845
cdf(dist, 2)
#> [1] 0.33994
quantile(dist, 0.5)
#> [1] 3.868233

generate(dist, 10)
#> [[1]]
#>  [1] -0.2304999  7.5325789  3.5676560  5.2909642  6.9210620 -1.4435118
#>  [7]  3.6515062 -0.5242521  7.2493561  9.9458747
#> 

# Quantile mixture (Vincentization) of two normal distributions
vdist <- dist_mixture(
  dist_normal(0, 1), dist_normal(5, 2),
  weights = c(0.3, 0.7), type = "quantile"
)
vdist
#> <distribution[1]>
#> [1] mixture<q>(0.3*N(0, 1), 0.7*N(5, 4))

mean(vdist)
#> [1] 3.5
variance(vdist)
#> [1] 2.89

density(vdist, 2)
#> [1] 0.1590017
cdf(vdist, 2)
#> [1] 0.188793
quantile(vdist, 0.5)
#> [1] 3.5