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?
mvrnormfunction from theMASSpackage. The essential options aremuwhich is a vector of the means andSigmawhich is the covariance matrix. – COOLSerdash Sep 05 '13 at 09:29rmvnorm()in themvtnormpackage as well. – Sep 05 '13 at 14:46mvrnormwill not (directly) do that. – whuber Sep 05 '13 at 16:17rmvnorm()command instead of usingrnorm()you can do it directly. See my answer below. – Sep 05 '13 at 18:20