R/rmix.norm.R

rmix.norm <-
function (n,alpha,mu,sigma=rep(1,length(alpha))) 
#n:      sample size.
#alpha:  vector of mixture probabilities.
#mu:     vector of means of each component.
#sigma:  vector of standard deviation of each component.
{
	m=length(alpha)
	alpha=alpha/sum(alpha)
	data=c()

	nindex=rmultinom(1,n,alpha)

	for( i in 1:m)
		data=c(data,rnorm(nindex[i],mu[i],sigma[i]))
	data
}

Try the MixtureInf package in your browser

Any scripts or data that you put into this service are public.

MixtureInf documentation built on May 2, 2019, 3:32 p.m.