Skip to contents

A shim of mvrnorm to return matrix when n < 2.

Usage

rmvn(n = 1L, mu, Sigma, ...)

Arguments

n

number of random vectors desired (nonnegative integer, can be 0).

mu

mean vector.

Sigma

variance-covariance matrix.

...

other arguments passed to mvrnorm.

Value

A matrix with n rows and length(mu) columns.

Author

Peter Solymos

See also

Examples

rmvn(0, c(a=0, b=0), diag(1, 2, 2))
#>      a b
rmvn(1, c(a=0, b=0), diag(1, 2, 2))
#>               a         b
#> [1,] 0.07367677 0.5774976
rmvn(2, c(a=0, b=0), diag(1, 2, 2))
#>              a          b
#> [1,] 2.7525866  0.6731855
#> [2,] 0.3517842 -0.9324766

sapply(0:10, function(n) dim(rmvn(n, c(a=0, b=0), diag(1, 2, 2))))
#>      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11]
#> [1,]    0    1    2    3    4    5    6    7    8     9    10
#> [2,]    2    2    2    2    2    2    2    2    2     2     2