Re: [R] Generating random variables with given pairwise correlations

2014-05-26 Thread Greg Snow
For numeric/continuous/normal values you can use the mvrnorm function in the MASS package (set the empirical argument to TRUE to force the exact correlation). Some would argue that you should not compute correlations with binary variables, but you could generate 4 normals, then take the last 2 and

[R] Generating random variables with given pairwise correlations

2014-05-24 Thread Sourav Ghosh
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