# Generating samples of correlated normally distributed variables with some of the variables pre-selected

I would greatly appreciate any of you who could help me with this challenge. I am going to state the problem in sequential order, so as to make it clear:

1. I have $n$ normally distributed random variables.

2. I have statistical data for each random variable (thus, their mean and variance).

3. I have historical data for each of the random variables, and from these data I can calculate the correlation between the random variables.

Now, assuming I know the value of one of the variables, how do I select the values of the other variables, such that all the $n$ values in the resulting vector are correlated accordingly. If that is possible, how do I extend this to a situation where I have two or more known values? For example, I know two or more values out of the $n$ variables (they satisfy the correlation constraint), and want to pick the others so that they also satisfy the correlation and their respective distribution functions.

I am not well-versed in statistics, so I would appreciate explanations that are as simple to understand as possible.

We're going to have to explain this using vectors and matricies.

Take a look at the 'Conditional distributions' section of the wikipedia page: https://en.wikipedia.org/wiki/Multivariate_normal_distribution#Correlations_and_independence

We have a multivariate normal distribution over the variable $x$ with mean $\mu$ and covariance $\Sigma$. We want to condition it on some elements of $x$ being known. Let's say we can break $x$ up into two parts

$$x = \left( \begin{array}{c} x_1 \\ x_2 \end{array} \right)$$

where we know $x_2 = a$.

We'll break up our mean and covariance similarly,

$$\mu = \left( \begin{array}{c} \mu_1 \\ \mu_2 \end{array} \right)$$

$$\Sigma = \left( \begin{array}{cc} \Sigma_{11} & \Sigma_{12} \\ \Sigma_{21} & \Sigma_{22} \end{array}\right)$$

In this case, the new distribution over $x_1$ given that $x_2 = a$ has mean $$\mu_{new} = \mu_1+\Sigma_{12}\Sigma_{22}^{-1}(a - \mu_2)$$ and covariance $$\Sigma_{new} = \Sigma_{11} - \Sigma_{12}\Sigma_{22}^{-1}\Sigma_{21}$$

That's the standard answer. However if you're not comfortable with matricies and vectors then this may need more explanation...

• Thanks! I think that explanation is good enough ... I will try it out and see how it goes. By the way is there a some code that implements these kind of calculation in python? Thanks Commented Nov 16, 2012 at 20:24