Suppose we have
$$X_1 \sim \textrm{unif}(n,0,1),$$
$$X_2 \sim \textrm{unif}(n,0,1),$$
where $\textrm{unif}(n,0,1)$ is uniform random sample of size n,
and
$$Y=X_1,$$
$$Z = 0.4 X_1 + \sqrt{1 – 0.4}X_2.$$
Then the correlation between $Y$ and $Z$ is $0.4$.
How can I extend this to three variables: $X_1$, $X_2$, $X_3$?
Best Answer
The question contains several errors as noted in comments - as defined in the question, Z is neither uniform nor has the specified correlation.
cardinal mentions copulas, and that's the most general way to go about it. However, there are several quite easy ways to get correlated uniforms (which can be seen as mere shortcuts to different kinds of copulas).
So let's start with some ways to get a pair of correlated uniforms.
1) If you add two uniforms the result is triangular, not uniform. But you can use the cdf of the resulting variable as a transform to take the result back to a uniform. The result isn't linearly correlated any more, of course.
Here's an R function to transform a symmetric triangular on (0,2) to standard uniform
Let's check that it does give a uniform
And it's correlated with u1 and u2:
but not linearly, due to the monotonic transformation to uniformity
With this as a tool we can generate some additional variables to get three equicorrelated uniforms:
The relationship between the v-variables all look like this:
--
A second alternative is to generate by taking a mixture. Instead of summing uniforms, take them with fixed probabilities.
e.g.
Which can again be used to generate multiple correlated uniforms.
--
A third simple approach is to generate correlated normals and transform to uniformity.
So now we convert to uniform:
One nice thing about methods 2 and 3 is that you get plenty of variety in your choice of how correlated things might be (and they don't have to be equicorrelated like the examples here).
There's a large variety of other approaches of course, but these are all quick and easy.
The tricky part is getting exactly the desired population correlation; it's not quite so simple as when you just want correlated Gaussians. Quantibex's answer at Generate pairs of random numbers uniformly distributed and correlated gives an approach that modifies my third method here which should give about the desired population correlation.