I am trying to create a dataset where columns 2,3,4 are correlate (0.98,0.97,0.96, respectively) to column 1. Right now I have this code:
library(MASS)
X<-mvrnorm(20,mu=c(5,6),Sigma=matrix(c(1,0.98,0.98,1),ncol=2),empirical=TRUE)
cor(X)
Y<-mvrnorm(20,mu=c(5,6),Sigma=matrix(c(1,0.97,0.97,1),ncol=2),empirical=TRUE)
cor(Y)
Y <- Y[,2]
Z<-mvrnorm(20,mu=c(5,6),Sigma=matrix(c(1,0.97,0.97,1),ncol=2),empirical=TRUE)
cor(Z)
Z <- Z[,2]
data <- cbind (X,Y,Z)
cor(data)
and it produces this matrix:
Y Z
1.00000000 0.9800000000 0.0826655886 -0.4293286
0.98000000 1.0000000000 0.0009559618 -0.5221029
Y 0.08266559 0.0009559618 1.0000000000 0.1847887
Z -0.42932859 -0.5221029358 0.1847886713 1.0000000
I would like the final outcome to look like this. It doesn't matter how the column 2,3,4 are correlated with each other (i.e. the X), as long as they have the right correlation with the first column.
1 0.98 0.97 0.96
0.98 1 X X
0.97 X 1 X
0.96 X X 1
Thanks for your help!