Simulate from Multivariate (repeated measures) Mixtures of Normals
rmvnormmix.RdSimulate from a mixture of multivariate zero-correlation normal distributions
Arguments
- 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\times r\), where \(m\) is the number of components (subpopulations) and \(r\) is the number of coordinates (repeated measurements) per case. Note:
muis 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:sigmais 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.
Details
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.
Value
rmvnormmix returns an \(n\times 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.
Examples
##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)
#> iteration 1 lambda 0.515 0.485 time 0.001
#> iteration 2 lambda 0.5078 0.4922 time 0.001
#> iteration 3 lambda 0.5018 0.4982 time 0.001
#> iteration 4 lambda 0.4969 0.5031 time 0.001
#> iteration 5 lambda 0.4932 0.5068 time 0.002
#> iteration 6 lambda 0.4903 0.5097 time 0.001
#> iteration 7 lambda 0.4881 0.5119 time 0.001
#> iteration 8 lambda 0.4864 0.5136 time 0.001
#> iteration 9 lambda 0.4851 0.5149 time 0.002
#> iteration 10 lambda 0.4842 0.5158 time 0.001
#> iteration 11 lambda 0.4834 0.5166 time 0.001
#> iteration 12 lambda 0.4829 0.5171 time 0.002
#> iteration 13 lambda 0.4824 0.5176 time 0.001
#> iteration 14 lambda 0.4821 0.5179 time 0.001
#> iteration 15 lambda 0.4818 0.5182 time 0.002
#> iteration 16 lambda 0.4816 0.5184 time 0.001
#> iteration 17 lambda 0.4815 0.5185 time 0.001
#> iteration 18 lambda 0.4814 0.5186 time 0.002
#> iteration 19 lambda 0.4813 0.5187 time 0.001
#> iteration 20 lambda 0.4812 0.5188 time 0.001
#> iteration 21 lambda 0.4812 0.5188 time 0.001
#> iteration 22 lambda 0.4811 0.5189 time 0.002
#> iteration 23 lambda 0.4811 0.5189 time 0.001
#> iteration 24 lambda 0.4811 0.5189 time 0.001
#> iteration 25 lambda 0.4811 0.5189 time 0.001
#> iteration 26 lambda 0.4811 0.5189 time 0.002
#> iteration 27 lambda 0.4811 0.5189 time 0.001
#> iteration 28 lambda 0.481 0.519 time 0.001
#> iteration 29 lambda 0.481 0.519 time 0.002
#> iteration 30 lambda 0.481 0.519 time 0.001
#> iteration 31 lambda 0.481 0.519 time 0.001
#> iteration 32 lambda 0.481 0.519 time 0.002
#> iteration 33 lambda 0.481 0.519 time 0.001
#> iteration 34 lambda 0.481 0.519 time 0.001
#> iteration 35 lambda 0.481 0.519 time 0.002
#> iteration 36 lambda 0.481 0.519 time 0.003
#> iteration 37 lambda 0.481 0.519 time 0.001
#> iteration 38 lambda 0.481 0.519 time 0.002
#> iteration 39 lambda 0.481 0.519 time 0.001
#> iteration 40 lambda 0.481 0.519 time 0.001
#> iteration 41 lambda 0.481 0.519 time 0.001
#> iteration 42 lambda 0.481 0.519 time 0.002
#> iteration 43 lambda 0.481 0.519 time 0.001
#> iteration 44 lambda 0.481 0.519 time 0.001
#> iteration 45 lambda 0.481 0.519 time 0.001
#> iteration 46 lambda 0.481 0.519 time 0.002
#> iteration 47 lambda 0.481 0.519 time 0.001
#> iteration 48 lambda 0.481 0.519 time 0.001
#> iteration 49 lambda 0.481 0.519 time 0.002
#> iteration 50 lambda 0.481 0.519 time 0.001
#> iteration 51 lambda 0.481 0.519 time 0.001
#> iteration 52 lambda 0.481 0.519 time 0.002
#> iteration 53 lambda 0.481 0.519 time 0.001
#> lambda 0.481 0.519, total time 0.071 s