#Draw samples from a Mixture of normal density library(MCMCpack) N<-10 #Number of mixture components D<-1 #p[j]~Dirichlet(D,...,D) sig1<-.5 sig2<-1 y<-seq(-5,5,.01) par(mfrow=c(3,3),mar=c(0,0,0,0)) for(i in 1:9){ theta<-rnorm(N,0,sig2) p<-rdirichlet(1,rep(D,N)) pdf<-y*0 for(j in 1:N){ pdf<-pdf+p[j]*dnorm(y,theta[j],sig1) } plot(y,pdf,type="l") }