Fast simulation from multivariate Gaussian probability distribution.

rmvnormal(n, mu, sigma)

Arguments

n

An integer giving the number of observations to be simulated.

mu

A numeric vector of dimension \(p\) giving the means of normal distribution.

sigma

A variance-covariance matrix of dimension \(p\) times \(p\).

Value

Returns a \(n\) by \(p\) matrix of observations from a multivariate normal distribution with the given mean mu and covariance

Details

The rmvnormal function is copied from the GMCM-package. It is similar to rmvnorm from the mvtnorm-package.

Author

Anders Ellern Bilgrau

Examples


rmvnormal(n = 10, mu = 1:4, sigma = diag(4))
#>            [,1]      [,2]     [,3]     [,4]
#>  [1,] 2.1303218 3.4041029 3.381102 3.145886
#>  [2,] 0.3396274 0.9434245 2.493076 3.989424
#>  [3,] 1.2866435 2.9511507 3.093893 4.751414
#>  [4,] 3.6857161 1.6012927 1.796961 5.202637
#>  [5,] 1.2132007 2.1696589 2.284323 4.079880
#>  [6,] 0.8484295 2.1845110 2.732680 4.022050
#>  [7,] 1.2997208 2.4429821 4.068646 3.275814
#>  [8,] 3.1325407 0.6456802 4.251484 3.850832
#>  [9,] 1.4427332 3.0928139 3.349427 5.172616
#> [10,] 1.4154192 1.7219600 2.510189 3.772807