I want to generate 2 continuous random variables Q1, Q2 (quantitative traits) and 2 binary random variables Z1, Z2 (binary traits) with given pairwise correlations between all possible pairs of them. Say (Q1,Q2):0.23, (Q1,Z1):0.55, (Q1,Z2):0.45, (Q2,Z1):0.4, (Q2,Z2):0.5, (Z1,Z2): 0.47

Please help me generate such data in R.


I have never tried but I think that you can use the Cholesky decomposition.

Generate your variables independently and then multiply the matrix obtained using all the variables for the cholesky decomposition of the covariance matrix that you would like to obtain.

This works when all the variables are normal. Not sure if it work on binary variable. Anyway you can easily try

  • $\begingroup$ Let me know how does it go $\endgroup$ – Donbeo May 24 '14 at 16:37
  • $\begingroup$ This indeed works with Normal variables but does not work generally. $\endgroup$ – P.Windridge Aug 29 '14 at 17:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.