Creates an S3 object representing a finite mixture distribution. The density is \(f(x) = \sum_{k=1}^{K} w_k f_k(x)\) where \(f_k\) are the component densities and \(w_k\) are the mixing weights.

mixture(components, weights)

Arguments

components

A non-empty list of dist objects.

weights

A numeric vector of non-negative mixing weights that sum to 1 (within tolerance 1e-10). Must have the same length as components.

Value

A mixture object with appropriate class hierarchy.

Details

The class hierarchy is determined by the components: if all components are univariate (or multivariate, continuous, discrete), the mixture inherits those classes as well.

Examples

m <- mixture(
  components = list(normal(0, 1), normal(5, 2)),
  weights = c(0.3, 0.7)
)
mean(m)
#> [1] 3.5
vcov(m)
#> [1] 6.95
format(m)
#> [1] "Mixture distribution (2 components)"