I am trying to create random covariance matrices for three joint gaussian variables. My goal is to sample random covariances matrices that always have correlation between 0.7 and 0.9 (or 0 if there isn’t).
So far I am doing it manually with a repeat
until is.positive.definite
is true… But I am unable to achieve it, my repeat
takes a lot of time because most of my matrices samples return false for the positive.definite.
Is there a library to do this or an simpler approach for this?
On the math side I know I can have correlation between: $X_1$ and $X_2$. $X_2$ and $X_3$. $X_1$ and $X_3$ If I am not mistaken, I can have correlation between the three pair or just one pair, there shouldn’t be any issue. But if there is correlation between two of them, the remaining correlation couldn’t be 0, otherwise the matrix would never be positive definite…
Best Answer
In the current question, this R function can be called until all constraints are satisfied. The matrix $\Xi$ (denoted
D
in rgwish) can be chosen towards favouring the constraints to be met.