Search code examples
rcorrelationnormal-distribution

Create all possible correlation matrices for 3 variables


I would like to simulate 3 variables (normally distrubted with mean=1 and sd=1) that have a specific correlation structure.

For each variable I would like to go through the correlation values 0.1 to 0.9 with increments of 0.1

SO possible correlations of the three variables would be

X1  X2  X3
0.1 0.1 0.1
0.1 0.1 0.2
0.1 0.1 0.3
..
0.9 0.9 0.9

In the end I would like to use these three correlation values to construct a variance-covariance matrix.

Is there an easy way to do this?


Solution

  • Try the r package mvtnorm.

    Define your correlation matrix s, and simulate the variable like this:

    x<-rmvnorm(n, mean = rep(0, nrow(sigma)), sigma = s)
    

    Now you can construct a loop, and go through all combinations of s, which you want.