Simulate from Mixtures of Normals
Simulate from a mixture of univariate normal distributions.
rnormmix(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 (subpopulations). This is assumed to sum to 1; if not, it is normalized. |
mu |
Vector of means. |
sigma |
Vector of standard deviations. |
This function simply calls rmvnormmix
.
rnormmix
returns an n-vector sampled from an m-component
mixture of univariate normal distributions.
##Generate data from a 2-component mixture of normals. set.seed(100) n <- 500 lambda <- rep(1, 2)/2 mu <- c(0, 5) sigma <- rep(1, 2) mixnorm.data <- rnormmix(n, lambda, mu, sigma) ##A histogram of the simulated data. hist(mixnorm.data)
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.