I have a function that returns normal distributed random numbers (let's call a single number X) when I pass the parameters mean and standard deviation. What I want is another function that generates normal distributed values (another, second mean / standard deviation) that are correlated to X with a given correlation coefficient (for example 0.8). How can I do this only with scalar functions (no vector / no matrix)?


If you have $X_1 \sim$ normal$(\mu_1, \sigma^2_1)$ then you could consider letting $X_2 := a X_1 + b + \epsilon$ where $\epsilon \sim$ normal$(0, \sigma^2_\epsilon)$ and is independent of $X_1$. Then $X_2 \sim$ normal$(\mu_2, \sigma^2_2)$ and $\text{Corr}(X_1, X_2) = \rho$ where

\begin{align} \mu_2 &= a \mu_1 + b \\ \sigma^2_2 &= a^2 \sigma^2_1 + \sigma^2_\epsilon \\ \rho &= \frac{a \sigma_1}{\sqrt{a^2 \sigma^2_1 + \sigma^2_\epsilon}} . \end{align}

If $\mu_2, \sigma^2_2$ and $\rho$ are fixed then you have three equations and three free parameters $a, b$ and $\sigma^2_\epsilon$, at which point you only need to do some algebra to find the right transformation.

  • $\begingroup$ Wow. This looks very good. :) Only for information and theoretical aspects: Does this method has a name? Where can I find more information about that like why these formulars are true? $\endgroup$ – ScientiaEtVeritas Feb 17 '16 at 16:29
  • $\begingroup$ I don't believe it has a name. Just consider that correlation measures linear relationships between random variables, so if you already have one it's natural to try applying a linear transformation with some noise to get the other. After that point the formulas above can be derived by hand. However, bear in mind we were assuming everything is normal here. This won't work in general since $X_2$ need not belong to the right family after the transformation. $\endgroup$ – dsaxton Feb 17 '16 at 16:36
  • $\begingroup$ Thank you for clarification. :) Just one question left. What about the last equation, the correlation coefficient? I unsuccessfully tried to understand the origin of that... $\endgroup$ – ScientiaEtVeritas Feb 17 '16 at 22:32
  • $\begingroup$ We already have the standard deviations for $X_1$ and $X_2$, so we only need to find their covariance which is $\text{Cov}(X_1, aX_1 + b + \epsilon) = a \text{Cov}(X_1, X_1) = a \sigma_1^2$ where we've used linearity of covariance and independence. If you divide this by the product of the standard deviations you get the formula for $\rho$. $\endgroup$ – dsaxton Feb 17 '16 at 23:00
  • $\begingroup$ So, I get it. But the product of standard deviations means that there is a $\sigma_1$ missing in the denominator, isn't it? $\endgroup$ – ScientiaEtVeritas Feb 17 '16 at 23:50

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.