1
$\begingroup$

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.

$\endgroup$
4
  • 3
    $\begingroup$ In what way was mvtnorm unsuccessful?! $\endgroup$ Commented Nov 8, 2015 at 9:27
  • 1
    $\begingroup$ Is your problem that the sample correlation isn't identical to your specified (population) correlation? $\endgroup$
    – Glen_b
    Commented Nov 8, 2015 at 16:18
  • $\begingroup$ @Glen_b yes, somehow. $\endgroup$ Commented Nov 11, 2015 at 19:43
  • 1
    $\begingroup$ 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. $\endgroup$
    – Glen_b
    Commented Nov 11, 2015 at 22:15

3 Answers 3

1
$\begingroup$

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.

$\endgroup$
4
  • $\begingroup$ 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)? $\endgroup$
    – whuber
    Commented Nov 8, 2015 at 14:48
  • $\begingroup$ 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 $\endgroup$ Commented Nov 8, 2015 at 15:25
  • 1
    $\begingroup$ Why not suggest PCA? $\endgroup$
    – whuber
    Commented Nov 8, 2015 at 16:13
  • $\begingroup$ @P.Windridge nice. would you please represent it with an example in R? $\endgroup$ Commented Nov 11, 2015 at 20:15
0
$\begingroup$

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.

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

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)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.