# Sampling with specified covariance matrix and distribution

Given a positive semi-definite $$n\times n$$ matrix $$C$$ I would like to construct $$n$$ random variables $$X_1,\dots,X_n$$ drawn from $$n$$ fixed distributions such that $$\mathrm{corr}(X_i,X_j) = C_{ij}$$. I am particularly interested in the case when $$X_i$$ are drawn from triangular distributions with varying parameters. I have read about two approaches

1. Cholesky decomposition: this seems appropriate to transform from uncorrelated sample to correlated samples. However, linear combinations of triangular distributions are no longer triangular
2. Using the cdf to transform the distributions to uniform or normal distributions, but this does not seem to preserve correlations

Is there any way how these approaches can be combined to guarantee that the random variables both obey the correlation and distribution condition? Suggestions for implementation in python are also appreciated

• Another word to add to your search is "copula". Maybe check out flr-project.org/FLa4a/reference/mvrtriangle.html, or for a python package sdv.dev/Copulas/index.html Apr 8 at 13:50
• It depends on what you might mean by "triangular distributions with varying parameters." One sense is that a triangular distribution arises by summing two independent Uniform(0,1) variables and the "parameters" are a location and scale. Because those parameters do not affect correlations, varying the parameters is irrelevant. Moreover, because a triangular distribution is close to Normal for these purposes, your method (2) works remarkably well. Could you therefore please clarify your meaning?
– whuber
Apr 8 at 15:31
• By parameters I mean the min, max and mode of the triangular distributions. Varying parameters just wanted to say that the variables are not necessarily identically distributed. So $X_1$ and $X_2$ would both follow a triangular distribution, but with different min,max and mode in general. Apr 9 at 14:23
• The min and max are irrelevant, because a change of location and scale can always make them equal to 0 and 1 without changing any correlations. Varying the mode is a complication that I believe is sufficiently severe that all you can hope for are approximate numerical solutions. Nevertheless, if the modes typically are near 1/2, my earlier comment applies: you will likely find that method (2) gives excellent results.
– whuber
Apr 10 at 15:33