NormalMix function

Mixture of normal distributions

Mixture of normal distributions

Density, distribution function and random generation for the mixture of normal distributions.

dmixnorm(x, mean, sd, alpha, log = FALSE) pmixnorm(q, mean, sd, alpha, lower.tail = TRUE, log.p = FALSE) rmixnorm(n, mean, sd, alpha)

Arguments

  • x, q: vector of quantiles.

  • mean: matrix (or vector) of means.

  • sd: matrix (or vector) of standard deviations.

  • alpha: matrix (or vector) of mixing proportions; mixing proportions need to sum up to 1.

  • log, log.p: logical; if TRUE, probabilities p are given as log(p).

  • lower.tail: logical; if TRUE (default), probabilities are P[Xx]P[X \le x]

    otherwise, P[X>x]P[X > x].

  • n: number of observations. If length(n) > 1, the length is taken to be the number required.

  • p: vector of probabilities.

Details

Probability density function

f(x)=α1f1(x;μ1,σ1)++αkfk(x;μk,σk)f(x)=α[1]f1(x;μ[1],σ[1])++α[k]fk(x;μ[k],σ[k]) f(x) = \alpha_1 f_1(x; \mu_1, \sigma_1) + \dots + \alpha_k f_k(x; \mu_k, \sigma_k)f(x) = \alpha[1] * f1(x; \mu[1], \sigma[1]) + \dots + \alpha[k] * fk(x; \mu[k], \sigma[k])

Cumulative distribution function

F(x)=α1F1(x;μ1,σ1)++αkFk(x;μk,σk)F(x)=α[1]F1(x;μ[1],σ[1])++α[k]Fk(x;μ[k],σ[k]) F(x) = \alpha_1 F_1(x; \mu_1, \sigma_1) + \dots + \alpha_k F_k(x; \mu_k, \sigma_k)F(x) = \alpha[1] * F1(x; \mu[1], \sigma[1]) + \dots + \alpha[k] * Fk(x; \mu[k], \sigma[k])

where sum(α[i])==1sum(\alpha[i]) == 1.

Examples

x <- rmixnorm(1e5, c(0.5, 3, 6), c(3, 1, 1), c(1/3, 1/3, 1/3)) hist(x, 100, freq = FALSE) curve(dmixnorm(x, c(0.5, 3, 6), c(3, 1, 1), c(1/3, 1/3, 1/3)), -20, 20, n = 500, col = "red", add = TRUE) hist(pmixnorm(x, c(0.5, 3, 6), c(3, 1, 1), c(1/3, 1/3, 1/3))) plot(ecdf(x)) curve(pmixnorm(x, c(0.5, 3, 6), c(3, 1, 1), c(1/3, 1/3, 1/3)), -20, 20, n = 500, col = "red", lwd = 2, add = TRUE)
  • Maintainer: Tymoteusz Wolodzko
  • License: GPL-2
  • Last published: 2023-11-30