Generate random numbers from a multivariate normal distribution. It can be used to create correlated random numbers.

multi_rnorm(n, mean, sd)

Arguments

n

The number of samples desired for each variable.

mean

A vector giving the mean of each variable.

sd

A valid covariance matrix.

Value

A matrix with n rows and as many columns as mean values.

Examples

mus <- c(0, 3, 5) sigmas <- matrix(c(1, 0.265, 2.19, 0.265, 0.25, 0.66, 2.19, 0.66, 9), ncol = 3) mat <- multi_rnorm(100, mus, sigmas) var(mat)
#> [,1] [,2] [,3] #> [1,] 1.0749718 0.2722898 2.643164 #> [2,] 0.2722898 0.2332673 0.716500 #> [3,] 2.6431635 0.7165000 11.309317