R/rand_MVN.R

Defines functions rand_MVN

Documented in rand_MVN

#' Simulate N realizations of X ~ MVN(mu,Sigma)
#'
#' @param mu A n by 1 column vector
#' @param Sigma A n by n matrix
#' @param N An integer
#'
#' @export
rand_MVN <- function(mu, Sigma, N) {
  sol <- c()
  L <- chol(Sigma)
  for(i in 1:N) {
    z <- rnorm(length(mu), mean = 0, sd = 1)
    z <- mu + (L%*%z)
    sol <- cbind(sol,z)
  }
  return(sol)
}
jcorrett/stats230.Rpackage documentation built on March 21, 2022, 5:36 a.m.