Learn R Programming

mixtools (version 0.1.0)

normmix.sim: 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

Run this code
##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)

Run the code above in your browser using DataLab