I need to generate 4 random variables that show a predefined correlation structure Sigma AND where certain values of Vars 1-4 are fixed.

As an illustrative example, consider the variables:

Var1 <- c(5, 8, 6, 7, 5, ., ., ., ., .)
Var2 <- c(., ., ., ., ., 8, 5, 7, 8, 9)
Var3 <- c(15, 17, 13, 27, 13, ., ., ., ., .)
Var4 <- c(., ., ., ., ., 18, 25, 14, 32, 2)

Now I want to 'fill in' the dots with some variable values in such way that the correlation structure between the variables is close to some predefined correlation matrix Sigma, but keeping/fixing the 'known' values (e.g., keeping values 5, 8, 6, 7, 5 for Var1 on rows/positions 1 to 5, etc).

I know it is straightforward to generate random variables in line with some predefined correlation matrix Sigma (using Cholesky decomposition, see e.g., Generate a random variable with a defined correlation to an existing variable), but is there any way to fix some of the values of multiple variables?

Any help is much appreciated!

  • 1
    $\begingroup$ In which sense does your question differ from simulating from a conditional distribution $f(x_1,x_2|x_3,x_4)$ associated with a joint distribution $f(x_1,x_2,x_3,x_4)$ where the correlation matrix $\Sigma$ is given? $\endgroup$
    – Xi'an
    Dec 29, 2014 at 17:46
  • $\begingroup$ Have you thought of using an MCMC simulator, like WinBUGS? You define the distributions of the variables, define the covariance matrix, and then input the variables as vectors with missing data for the corresponding values. After a burn-in period you should be able to take any of the simulations you want. $\endgroup$ Dec 29, 2014 at 21:56
  • $\begingroup$ Do you want the given population correlation, or are you aiming to achieve it exactly as a sample correlation? $\endgroup$
    – Glen_b
    Dec 30, 2014 at 1:48

1 Answer 1


I assume you want Gaussian random variables -- if not, the Cholesky approach isn't sufficient and in general you'll probably want to compute actual conditional distributions.

In effect, you just need to compute the correct conditional distribution in each case. You can either work directly with standardized variables and correlation matrices or unstandardized variables and covariances. Since you mention the correlation matrix I'll assume the first.

You have 5 points for which you have Var1 and Var3 and 5 for which you have Var2 and Var4:

   Var1 Var3 Var2 Var4
1     5   15   NA   NA
2     8   17   NA   NA
3     6   13   NA   NA
4     7   27   NA   NA
5     5   13   NA   NA
6    NA   NA    8   18
7    NA   NA    5   25
8    NA   NA    7   14
9    NA   NA    8   32
10   NA   NA    9    2

So if you do a Cholesky of $\Sigma$ where the variables Var1 and Var3 come before the other two (for example in the order Var1, Var3, Var2, Var4), that will give you [Var2|Var1,Var3] (in standardized variables) and [Var4|Var1,Var3,Var2].

You can then do another Cholesky (for example in the order Var2, Var4, Var1, Var3) to generate the remaining 5 values.

If you had more complicated patterns of present and absent values, the same trick works but you may often be able to organize it so that you only need a small number of decompositions.

  • $\begingroup$ (+1) This would be my answer too. $\endgroup$
    – Xi'an
    Dec 30, 2014 at 13:44
  • $\begingroup$ Thanks a lot for the response, I think this is indeed the most straightforward solution! $\endgroup$
    – Willem
    Jan 3, 2015 at 13:12

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.