rmvnormmix | 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: |
sigma |
Matrix of standard deviations, same dimensions as |
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.
rnormmix
##Generate data from a 2-component mixture of trivariate normals. set.seed(100) n <- 200 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.