I start with a vector of random numbers sampled from a normal distribution:
R<-rnorm(100, mean=0, sd=30)
I would now like to create 3 variables that are correlated with each other with a pre-specified correlation. In addition I would like to have these three variables correlated with R
with a pre-specified correlation.
For example A
, B
, C
would have correlation 0.7 with each other, and A
, B
, C
would have correlation 0.6 with R
.
I.e. I am looking for the following covariance matrix:
R A B C
R 1 .6 .6 .6
A .6 1 .7 .7
B .6 .7 1 .7
C .6 .7 .7 1
How can this be done in R?