1

I am trying to generate a set 10 normally distributed random variables that are negatively correlated with each other with $\rho=-0.5$.

I've generated a covariance matrix S with 10's on the diagonals and -5's everywhere else using the following code (when I check the correlation matrix using cov2cor it has 1's on the diagonal and -0.5's everywhere else):

> S = matrix(-5, 10, 10)
> diag(S) <- 10
> S
      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
 [1,]   10   -5   -5   -5   -5   -5   -5   -5   -5    -5
 [2,]   -5   10   -5   -5   -5   -5   -5   -5   -5    -5
 [3,]   -5   -5   10   -5   -5   -5   -5   -5   -5    -5
 [4,]   -5   -5   -5   10   -5   -5   -5   -5   -5    -5
 [5,]   -5   -5   -5   -5   10   -5   -5   -5   -5    -5
 [6,]   -5   -5   -5   -5   -5   10   -5   -5   -5    -5
 [7,]   -5   -5   -5   -5   -5   -5   10   -5   -5    -5
 [8,]   -5   -5   -5   -5   -5   -5   -5   10   -5    -5
 [9,]   -5   -5   -5   -5   -5   -5   -5   -5   10    -5
[10,]   -5   -5   -5   -5   -5   -5   -5   -5   -5    10

My plan was to either use the Cholesky decomposition or to use the mvrnorm function to generate the variables. However, when I use mvrnorm I get an error saying that the matrix is not positive definite.

> mvrnorm(n=1, rep(5, 10), S)
Error in mvrnorm(n = 1, rep(5, 10), S) : 
  'Sigma' is not positive definite

When I check the eigenvalues, the last is, in fact, -35. My question is, what am I doing wrong?

BLimkins
  • 401
  • 3
  • 7
  • 5
    You've defined an impossible correlation structure. See http://math.stackexchange.com/questions/265685/pairwise-correlation-of-three-random-variables – Cliff AB Sep 22 '15 at 01:51
  • You can check that $S$, when applied to the vector $(1,1,\ldots,1)$, returns a negative multiple of that vector (provided the dimension of $S$ exceeds $3$). Thus $S$ cannot be a covariance matrix. For more about such issues, see http://stats.stackexchange.com/questions/69114, http://stats.stackexchange.com/questions/5747, http://stats.stackexchange.com/questions/124538, or [search our site](http://stats.stackexchange.com/search?q=correlation+positive+definite). – whuber Sep 22 '15 at 13:20

0 Answers0