normmix.sim {mixtools}R Documentation

Simulate from Mixtures of Normals

Description

Simulate from a mixture of univariate normal distributions.

Usage

normmix.sim(n, lambda, mu, sigma, m = 1)

Arguments

n Number of cases to simulate.
lambda Vector of mixture probabilities, with length equal to desired number of components. This is assumed to sum to 1; if not, it is normalized.
mu Vector of means.
sigma Vector of standard deviations.
m Number of repeated measurements per case.

Value

normmix.sim returns an nxm matrix in which each row is an i.i.d. sample from one of the components of a mixture of univariate normals. Every entry of the matrix has a marginal distribution equal to a mixture of normals, though there is dependence among observations in the same row due to the fact that the component is held fixed in each row.

See Also

makemultdata

Examples

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

n<-500
lambda<-rep(1, 2)/2
mu<-c(0, 5)
sigma<-rep(1, 2)
mixnorm.data<-normmix.sim(n, lambda, mu, sigma)

##A histogram of the simulated data.

hist(mixnorm.data)

[Package mixtools version 0.1.0 Index]