Draw random samples from multivariate normal distribution with variance given by a correlation matrix.
Arguments
- n
number of samples
- mean
matrix with mean values (either a 1xp or nxp matrix)
- cor
matrix with correlation (either a 1x((p-1)*p/2) or nx((p-1)*p/2) matrix. The correlation coefficients must be given in the order R(1,2), R(1,3), ..., R(1,p), R(2,3), ... R(2,p), ... where R(i,j) is the entry in row i and column j of the correlation matrix.
- var
Optional covariance matrix (instead of 'cor' argument)
Examples
rmvn(10, cor = rep(c(-0.999, 0.999), each = 5))
#> [,1] [,2]
#> [1,] 0.6400012 -0.6233286
#> [2,] -1.6044162 1.6863581
#> [3,] 1.5296363 -1.5347103
#> [4,] 1.3777884 -1.3535963
#> [5,] 0.4505255 -0.4960817
#> [6,] -0.3153914 -0.2654546
#> [7,] 0.5451713 0.6492686
#> [8,] -0.8878852 -0.8328810
#> [9,] -0.5709326 -0.6327175
#> [10,] -2.8987527 -2.8644639
