Generating correlated distributions with a certain mean and standard deviation? Given a distribution A with a mean of $\mu_1$ and standard deviation of $\sigma_1$, how can I generate:


*

*Distribution B with a mean of $\mu_2$ and standard deviation of $\sigma_2$ and a correlation of $X_1$ with distribution A

*Distribution C with a mean of $\mu_3$ and standard deviation of $\sigma_3$ and a correlation of $X_2$ with distribution B and $X_3$ with distribution A


Can someone please tell me if this even makes sense? My naive approach was the following:


*

*Generate A with the given parameters

*Generate B with the given parameters and then see if the generated values have the specified correlation with A. If not, regenerate B until this correlation is achieved.

*Generate C using the approach in Step 2.


However, I am not quite sure if this approach will terminate. Is there a better way to achieve this? I'd love to see an example in R. 
 A: If you mean the individual distributions are Gaussian, then sampling from a multivariate normal with mean vector $\mathbf{\mu}$ and covariance matrix $\mathbf{\Sigma}$ will generate such data.
Here is an R example using the function mvrnorm() in package MASS (which comes with R):
## means of individual distributions
mu1 <- 5
mu2 <- 10
mu3 <- 0
## variance
sigma1 <- 5
sigma2 <- 1
sigma3 <- 0.5
## Correlations
X1 <- 0.5
X2 <- 0.1
X3 <- 0.8

## load package
require("MASS")

We need to supply n, the number of values from each distribution, mu the mean vector, and Sigma the covariance matrix. In the code below I form these from the scalars entered above.
set.seed(1)
dat <- mvrnorm(100, mu = c(mu1, mu2, mu3),
               Sigma = matrix(c(sigma1, X1    ,     X3,
                                X1    , sigma2,     X2,
                                X3    , X2    , sigma3),
                              ncol = 3, byrow = TRUE),
               empirical = TRUE)

I used empirical = TRUE to specify empirical not population parameters for $\mathbf{\mu}$ and $\mathbf{\Sigma}$. This results in the covariance matrix of dat having exactly the values we specified:
R> cov(dat)
     [,1] [,2] [,3]
[1,]  5.0  0.5  0.8
[2,]  0.5  1.0  0.1
[3,]  0.8  0.1  0.5

as do the column means:
R> colMeans(dat)
[1]  5.000e+00  1.000e+01 -8.882e-18

If you use the default, empirical = FALSE, then you get random samples from a population which will have different sample mean vector and sample covariance matrix from the specified one as you have only seen n examples from that larger population:
set.seed(1)
dat2 <- mvrnorm(100, mu = c(mu1, mu2, mu3),
                Sigma = matrix(c(sigma1, X1    ,     X3,
                                 X1    , sigma2,     X2,
                                 X3    , X2    , sigma3),
                               ncol = 3, byrow = TRUE))

R> cov(dat2)
       [,1]    [,2]    [,3]
[1,] 4.0441 0.39858 0.61120
[2,] 0.3986 0.91110 0.04842
[3,] 0.6112 0.04842 0.48782
R> colMeans(dat2)
[1]  5.24138 10.06668  0.02448

