I have done mvn
simulation with the MASS
package.
Simulations should have the Mean and Variances of X
and Y
and a chosen correlation. SO far this works:
K=0.1
Sim <- data.frame(X,Y)
CovM <- matrix(data=c(var(X),(-k)*sd(X)*sd(Y),(-k)*sd(X)*sd(Y),var(Y),ncol=2,nrow=2)
MVSim <- mvrnorm(n, mu=colMeans(Sim), Sigma=CovM, empirical=TRUE)
Now I want to replicate the procedure with a for loop:
for(i in seq(1,m, by=2)){
MVSimOB[, i:(i+1)] <- mvrnorm(n, mu=colMeans(Sim), Sigma=CovM, empirical=TRUE)
But I get the following error message:
Sigma = matrix(c(var(SimYOB), :
Indices out of borders
The solution is probably very simple. But I do not understand why I first do not get an error, but replicating the procedure does not work. Thanks a lot for help!