Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

rnormmix

Simulate from Mixtures of Normals


Description

Simulate from a mixture of univariate normal distributions.

Usage

rnormmix(n, lambda=1, mu=0, sigma=1)

Arguments

n

Number of cases to simulate.

lambda

Vector of mixture probabilities, with length equal to m, the desired number of components (subpopulations). This is assumed to sum to 1; if not, it is normalized.

mu

Vector of means.

sigma

Vector of standard deviations.

Details

This function simply calls rmvnormmix.

Value

rnormmix returns an n-vector sampled from an m-component mixture of univariate normal distributions.

See Also

Examples

##Generate data from a 2-component mixture of normals.

set.seed(100)
n <- 500
lambda <- rep(1, 2)/2
mu <- c(0, 5)
sigma <- rep(1, 2)
mixnorm.data <- rnormmix(n, lambda, mu, sigma)

##A histogram of the simulated data.

hist(mixnorm.data)

mixtools

Tools for Analyzing Finite Mixture Models

v1.2.0
GPL (>= 2)
Authors
Derek Young [aut, cre] (<https://orcid.org/0000-0002-3048-3803>), Tatiana Benaglia [aut], Didier Chauveau [aut], David Hunter [aut], Ryan Elmore [ctb], Thomas Hettmansperger [ctb], Hoben Thomas [ctb], Fengjuan Xuan [ctb]
Initial release
2020-02-05

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.