R/rMCN.R

Defines functions rMCN

Documented in rMCN

rMCN <-
function(n, mu,Sigma, nu=0.5, gamma=0.5){
   if(is.null(n))
    stop("sample size must be specified")
  if(is.null(mu))
    stop("mu must be specified")
  if(is.null(Sigma))
    stop("Sigma must be specified")
    if(is.vector(Sigma)) Sigma=matrix(Sigma)
  if(round(n)!=n | n<=0)
    stop("sample size must be a positive integer")      
  if(!is.matrix(mu)) mu<-matrix(mu, ncol=length(mu),nrow=1)
  if (!isSymmetric(Sigma))
        stop("Sigma is not symmetric")
  if (min(eigen(Sigma)$values)<=0)
        stop("Sigma is not a positive-definite matrix")
  if (ncol(Sigma) != ncol(mu))
        stop("The dimension of mu does not agree with the dimension of Sigma")
  if (nu<0 | nu>1)
        stop("nu must be between 0 and 1")
  if (gamma<0 | gamma>1)
        stop("gamma must be between 0 and 1")
  p<-ncol(Sigma)
y<-matrix(0,n,p)
 for(i in 1:n){
        uu<-rbinom(1,1,nu)
        u<-gamma*uu+1-uu
      y[i,]=as.vector(mu)+MASS::mvrnorm(1,rep(0,p),Sigma/u)
  } 
    return(y)
  }

Try the skewMLRM package in your browser

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

skewMLRM documentation built on Nov. 24, 2021, 9:07 a.m.