R/rmvnormmix.R

Defines functions normmixrm.sim

Documented in normmixrm.sim

# Note:  normmixrm.sim is here for backwards compatibility
rmvnormmix <- normmixrm.sim <- function(n,lambda=1,mu=0,sigma=1) {
  m <- length(lambda) # nb of components
  mu <- matrix(mu, nrow=m)
  sigma <- matrix(sigma, nrow=m)
  if ((r <- NCOL(mu)) != NCOL(sigma)) {
    stop("mu and sigma must have the same number of columns", call.=FALSE)
  }
  z <- sample(m,n,replace=TRUE,prob=lambda) # component 
  matrix(rnorm(n*r,mean=as.vector(mu[z,]),sd=as.vector(sigma[z,])),n,r)  
}

Try the mixtools package in your browser

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

mixtools documentation built on Dec. 5, 2022, 5:23 p.m.