R/rcompnorm.R

Defines functions rcompnorm

Documented in rcompnorm

################################
#### Random values generation from a multivariate normal
#### distribution on the simplex
#### Tsagris Michail 02/2016
#### mtsagris@yahoo.gr
################################
rcompnorm <- function(n, m, s, type = "alr") {
  ## n is the sample size
  ## m is the mean vector in R^d
  ## s is the covariance matrix in R^d
  ## type is either alr or ilr
  x <- Rfast::rmvnorm(n, m, s)
  
  if ( type == "alr" ) {
    y <- cbind( 1, exp(x) )
  } else {
    D <- dim(x)[2]
    y <- x %*% helm(D + 1)
    y <- exp(y)
  }
  
  y / Rfast::rowsums(y)
}

Try the Compositional package in your browser

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

Compositional documentation built on Oct. 9, 2024, 5:10 p.m.