I want to generate uniform random variables which have a correlation structure defined by a graph i.e. a variable is only correlated with its neighbors in the graph and is uncorrelated with the rest conditional on its neighbors.

It seems that I should specify this as a precision matrix (and not a correlation matrix) with 0s entries for non-neighbors of a node; for simplicity lets also assume that the non-zero entries are distributed U(0,1). This is so since the precision matrix implies partial correlations and that’s what I should target as having 0 correlations in a graph. I hope that makes sense?

So, I have been thinking of this problem as a copula with margins given by uniform and the joint also a uniform with the correlation matrix as the inverse of the precision matrix above.

However,

1). The results that I get don’t seem to show the desired correlation structure.

2). It is computationally inefficient to invert a 50k*50k matrix in R.

Any thoughts on how I could efficiently do this while also assuring that the correlation matrix stays positive definite?

**Answer**

**Attribution***Source : Link , Question Author : Blade Runner , Answer Author : Community*