normmix.sim {mixtools} | R Documentation |
Simulate from a mixture of univariate normal distributions.
normmix.sim(n, lambda, mu, sigma, m = 1)
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. |
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.
##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)