Simulates a matrix where the rows are i.i.d. samples from a multivariate
normal distribution. Positive semidefinite covariances are supported,
including degenerate distributions with zero-variance directions.
Usage
rmvnorm(n, mu, Sigma, Sigma.chol = NULL)
Arguments
- n
nonnegative integer sample size
- mu
finite numeric multivariate mean vector
- Sigma
finite symmetric positive semidefinite covariance matrix
- Sigma.chol
optional finite square factor whose crossproduct is
Sigma; when supplied, this factor determines the covariance
Value
a matrix with n rows
Author
Cassy Dorff, Shahryar Minhas, Tosin Salau
Examples
set.seed(1)
mu <- c(0, 1)
Sigma <- matrix(c(1, 0.3, 0.3, 1), 2, 2)
draws <- rmvnorm(100, mu, Sigma)
colMeans(draws)
#> [1] 0.1088874 0.9965996