I would like to simulate data with different correlation matrices, with this method:
M = matrix(c(1.0, 0.6, 0.6, 0.6,
0.6, 1.0, -0.2, 0.0,
0.6, -0.2, 1.0, 0.0,
0.6, 0.0, 0.0, 1.0 ),
nrow=4, ncol=4)
Cholesky-decomposition
L = chol(M)
nvars = dim(L)[1]
Random variables:
r = t(L) %*% matrix(rnorm(nvars * megf), nrow=nvars, ncol=megf)
r = t(r)
It worked with positive correlations, but I also need negative. Why doesn't it work? How can I do that?