# r, How to create two correlated variables that are distributed jointly normal (mean 0, var 1) [duplicate]

I want to create two random variables $X \sim N(0,1)$ and $Y \sim N(0,1)$ that satisfy $E(X,Y)=0.5$

That is I want to create $Z=(X,Y)^\top$ with a joint bivariate normal distribution

$Z \sim N\left( \left(\begin{array}{c} 0\\ 0 \end{array}\right) , \left(\begin{array}{cc} 1 & 0.5\\ 0.5 & 1 \end{array}\right) \right)$.

How do I code this in R?

Thanks.

• This question appears to be off-topic give that it is mostly about R code.
– Andy
May 11, 2014 at 7:47
• What does $E(X,Y)$ mean? Did you mean $E(X \cdot Y)$? May 11, 2014 at 9:02
• This answer describes how this can be done using a Cholesky decomposition of the covariance matrix. Of course, you could use mvrnorm from MASS but it is less fun. May 11, 2014 at 9:08
• Duplicate. See here or here May 11, 2014 at 9:25

> library(mvtnorm)