Skip to contents

Draws from \(N(\mu, \Sigma)\) using the symmetric eigen decomposition, matching MASS::mvrnorm exactly – including its RNG consumption (rnorm(p * n) in the same order), so under a common seed the draws are identical.

Usage

morie_mvrnorm(n = 1, mu, Sigma, tol = 1e-06, empirical = FALSE)

Arguments

n

Number of samples.

mu

Mean vector (length p).

Sigma

p x p covariance matrix.

tol

Tolerance for the positive-definiteness check.

empirical

If TRUE, force the sample mean/covariance to match mu/Sigma exactly (as in MASS).

Value

A length-p vector when n == 1, else an n x p matrix.

References

Venables, W. N., & Ripley, B. D. (2002). Modern Applied Statistics with S. Springer.

Examples

set.seed(1)
morie_mvrnorm(3, mu = c(0, 0), Sigma = diag(2))
#>            [,1]       [,2]
#> [1,] -1.5952808 -0.6264538
#> [2,] -0.3295078  0.1836433
#> [3,]  0.8204684 -0.8356286