simmix {densup}R Documentation

Generate a random sample from a mixture of Gaussians

Description

Generate a random sample from a mixture of multivariate Gaussians. Gaussians have diagonal covariance matrices.

Usage

simmix(n, d, M, sig, p, seed)

Arguments

n positive integer; size of the sample to be generated
d positive integer; dimension of the vectors of the sample to be generated
M mixnum*d-matrix; rows of M are means of the gaussians in the mixture. We have a mixture of "mixnum" Gaussians, whose dimension is d.
sig mixnum*d-matrix; rows of sig are the diagonals of the covariance matrices of the mixtures.
p mixnum-vector; weights for the members of the mixture. The sum of elements of "p" is 1.
seed real number; seed for the random number generator.

Value

n*d-matrix: n samples from a d-dimensional distribution

Author(s)

Jussi Klemelä

Examples

d<-2
mixnum<-3
M<-matrix(0,mixnum,d)
M[1,]<-c(0,0)   
M[2,]<-c(4,0)  
M[3,]<-c(0,4)   
sig<-matrix(1,mixnum,d)
p0<-1/mixnum
p<-p0*rep(1,mixnum)
n<-10
dendat<-simmix(n,d,M,sig,p,seed=1)    

#             [,1]       [,2]
# [1,]  3.02537426 -1.9304081
# [2,] -0.56075523 -0.9490871
# [3,]  1.81607722 -1.5298516
# [4,]  0.08951152  4.8682471
# [5,]  0.96951953  2.0663557
# [6,] -0.44478838  4.5861246
# [7,] -0.02287879 -1.2559018
# [8,]  0.09960695  3.3340215
# [9,] -0.35515387  2.8956619
#[10,]  0.54290910  5.0220281      


[Package Contents]