# Create uncorrelated random multivariate normals

Creating correlated random variables is an easy task in R, especially the normal distribution. But what I need is to generate variables (for example 5 standard normals) with very low correlations (e.g., below 0.05). I tried mvtnorm package several times with no success.

I'm just curious, we use methods (like Cholesky decomposition) to transform uncorrelated variables into correlated. Can we do it the other way around?

Edit: I want a method that makes multiple "correlated" normal variables "extremely low correlated" without trial & error with a reasonable sample size (say 50) implemented in R.

• In what way was mvtnorm unsuccessful?! Commented Nov 8, 2015 at 9:27
• Is your problem that the sample correlation isn't identical to your specified (population) correlation? Commented Nov 8, 2015 at 16:18
• @Glen_b yes, somehow. Commented Nov 11, 2015 at 19:43
• Since I assume you realize that the sample correlation simply won't equal the population correlation, I think you're going to have to clarify what you need. Commented Nov 11, 2015 at 22:15

Suppose $X$ is multivariate normal.

Then by definition we can write $X = \mu + CZ$ for a (deterministic) vector $\mu$, matrix $C$ and random vector $Z$ of independent standard normal (i.e. $N(0,1)$) variables.

(So $\Sigma = CC^T$ is the covariance matrix).

Thus if $C$ is invertible then $$C^{-1}(X-\mu) = Z$$ is a vector of independent (and hence uncorrelated) standard normals.

Note, if you are given pos. def. $\Sigma$ upfront, then to calculate $C = (\Sigma^{1/2})^{-1}$ you would probably want to first calculate the square root (e.g. using Cholesky) and then invert that.

• I can't tell which question you are answering: are you trying to explain how to create correlated variables (which is the objective of the links you provide) or uncorrelated variables (which appears to be what is asked on the last line)?
– whuber
Commented Nov 8, 2015 at 14:48
• Yes on rereading that is probably what the OP wants, and the answer I linked to is the wrong way round -- will edit it later. In the meantime, short answer: yes you can go from (non-singular) multivariate normal to uncorrelated normal but you need to calculate the inverse square root of the covariance matrix Commented Nov 8, 2015 at 15:25
• Why not suggest PCA?
– whuber
Commented Nov 8, 2015 at 16:13
• @P.Windridge nice. would you please represent it with an example in R? Commented Nov 11, 2015 at 20:15

Independent random variables should by definition not be correlated, but if you are only generating a small number of points you'll get some correlation by chance. You should find as you generate a larger dataset that you get lower correlations.

If, for some reason, you need to generate a small dataset with extremely low correlations between your five variables, you might instead generate say 50 variables, calculate their correlation matrix and select 5 with the lowest correlation.

• thanks for the tip. by the way I was taking n=50 for each variable. Commented Nov 11, 2015 at 19:56

See this, where I borrowed the idea from. I think this is what you were asking for.

# Number of variables to make
n <- 5

# Correlation Matrix with .05 correlation for all
R <- matrix(.05, nrow = n, ncol = n)
diag(R) <- 1

# Cholesky decompostion of correlation matrix
Lut <- chol(R)
L <- t(Lut)

# Standard deviations
sds <- seq(10, 1, length.out = n)

# VCOV matrix
Sigma <- diag(sds) %*% L %*% Lut %*% diag(sds)

# Generate variables
library(MASS)
X <- mvrnorm(50, mu= rep(0, n), Sigma, empirical = TRUE)
cov(X)
cor(X)

X <- mvrnorm(500, mu= rep(0, n), Sigma, empirical = FALSE)
cov(X)
cor(X)