0

I am using the programming language Lua which does not have any built-in function for drawing samples from a multivariate Gaussian distribution. So I wonder, how can one implement a function that does the sampling for a multivariate Gaussian distribution? Note that I do have access to a function which can draw samples from a single-variable Gaussian distribution. Can I somehow use that function to draw samples for the multivariate case given a desired covariance matrix?

Also, if I'm not mistaken, I remember I read somewhere that one can draw samples from a single-variable Gaussian distribution as follow:

$\text{sample } = \mu + \sigma^2 \epsilon$

where $\mu$ is a mean, $\sigma^2$ is a variance and $\epsilon \sim U(0,1)$. Therefore, a generalization of the above equation for a multivariate Gaussian distribution is to have mean and [diagonal] covariance matrix. However, if not sure if this equation is valid by itself and whether it gives valid samples for a non-diagonal covariance matrix.

So I wonder, can you guys give me some insights on how one should go about generating samples for a multivariate Gaussian distribution given a desired non0diagonal covariance matrix and without having having access to a built-in function in a programming language? Also, I would appreciate your help to verify/prove the equation I wrote above.

buruzaemon
  • 123
  • 1
  • 1
  • 9
Amir
  • 634
  • 1
  • 6
  • 17
  • If you chose $\epsilon$ to be a vector, wouldn't $\sigma^2$ be the 2 by 2 covariance matrix? – sodiumnitrate May 16 '16 at 22:14
  • @sodiumnitrate You're right, but I'm just not sure whether those samples are going to be valid. So can someone give some proofs or reasoning on why those samples are valid? – Amir May 16 '16 at 22:18
  • 1
    Your equation is wrong; that would give samples with variance $\sigma^4$. There are numerous posts already on algorithms for generating from a multivariate Gaussian distribution, for example, via a Choleski decomposition. – Glen_b May 16 '16 at 23:16
  • 1
    An example is discussed [here](http://stats.stackexchange.com/questions/120179/generating-data-with-a-given-sample-covariance-matrix/120227#120227) in the paragraph beginning "In the first case...". Also see [here](http://stats.stackexchange.com/questions/38856/how-to-generate-correlated-random-numbers-given-means-variances-and-degree-of) (but which doesn't mention the mean-shift). – Glen_b May 16 '16 at 23:33
  • 1
    Also [here](http://stats.stackexchange.com/questions/111865/tool-for-generating-correlated-data-sets/112160#112160) and [here](http://stats.stackexchange.com/questions/89796/can-i-use-the-cholesky-method-for-generating-correlated-random-variables-with-gi/89830#89830) – Glen_b May 16 '16 at 23:49

0 Answers0