rmvnormmix {mixtools} | R Documentation |
Simulate from a mixture of multivariate zero-correlation normal distributions
rmvnormmix(n, lambda=1, mu=0, sigma=1)
n |
Number of cases to simulate. |
lambda |
Vector of mixture probabilities with length equal to m, the desired number of components. This is assumed to sum to 1; if not, it is normalized. |
mu |
Matrix of means of dimensions m x r, where
m is the number of components (subpopulations) and r is
the number of coordinates (repeated measurements) per case. Note: mu
is automatically coerced to a matrix with m rows even if it is not
given in this form, which can lead to unexpected behavior in some cases. |
sigma |
Matrix of standard deviations, same dimensions as mu .
The coordinates within a case are independent, conditional on the mixture
component. (There is marginal correlation among the coordinates, but
this is due to the mixture structure only.) Note: sigma is
automatically coerced to a matrix with m rows even if it is not
given in this form, which can lead to unexpected behavior in some cases. |
It is possible to generate univariate standard normal random variables using the default values (but why bother?). The case of conditionally iid coordinates is covered by the situation in which all columns in mu and sigma are identical.
rmvnormmix
returns an n x r matrix in which each row is
a sample from one of the components of a mixture of zero-correlation
multivariate normals. The mixture structure
induces nonzero correlations among the coordinates.
##Generate data from a 2-component mixture of trivariate normals. n <- 500 lambda <- rep(1, 2)/2 mu <- matrix(2*(1:6), 2, 3) sigma <- matrix(1,2,3) mydata<-rmvnormmix(n, lambda, mu, sigma) ## Now check to see if we can estimate mixture densities well: title <- paste("Does this resemble N(", mu[1,], ",1) and N(", mu[2,],",1)?", sep="") plot(npEM(mydata, 2), title=title)