mixtureDensity: A mixture of two or more distributions

View source: R/RVCompare.R

mixtureDensityR Documentation

A mixture of two or more distributions

Description

Returns the density function of the mixture distribution. The returned function is a single parameter function that returns the probability of the mixture in that point.

Usage

mixtureDensity(densities, weights = NULL)

Arguments

densities

the probability density functions to be combined.

weights

(optional) the weights of the distributions in the mixture. If it is not give, equal weights are assumed.

Value

Returns a callable function with a single parameter that returns the probability of the mixture distribution each point.

Examples

#If parameter weights not given, equal weights are assumed.
dist1 <- mixtureDensity(c(normalDensity(-2,1), normalDensity(2,1)))
plot(dist1, xlim = c(-5,5), xlab="x", ylab = "Probability density",
     main="Mixture of two Gaussians with equal weights", cex.main=0.85)

dist2 <- mixtureDensity(c(normalDensity(-2,1), normalDensity(2,1)), weights=c(0.8,0.2))
plot(dist2, xlim = c(-5,5), xlab="x", ylab = "Probability density",
     main="Mixture of two Gaussians with different weights", cex.main=0.85)

RVCompare documentation built on Aug. 21, 2023, 5:13 p.m.