Page 1 of 1

normal bivariate random generator

Posted: Thu Nov 13, 2008 10:02 am
by Philippe Rous
Hi everyone !

Is there some mean to get a random sample from a Normal Bi-variate distribution (known means, std.dev. and rho) ?

Thank you !

Regards

Phil

Re: normal bivariate random generator

Posted: Thu Nov 13, 2008 10:28 pm
by Gene
Hi everyone !

Is there some mean to get a random sample from a Normal Bi-variate distribution (known means, std.dev. and rho) ?

Thank you !

Regards

Phil
You want to generate an nx1 vector of normal random numbers u ~ N(0,S), where n x n S is the variance-covariance matrix of u. Let A'A = S, then A^-1u ~ N(0,I), where I is the n x n identity matrix. Notice e = A^-1 u ~ N(0,I) is rather easy to generate since each element of e is just iid normal. Just use @rnorm or nrnd to generate the elements of the e. After generating e you can transform e to u by the relationship u = A e. There are many A's that satisfies A'A = S. A popular way to decompose S is using Cholesky decomposition. Here I have an example of how to do this. (If u has non-zero means, you can add each column of u by its mean.)

Code: Select all

'S contain the !n x !n covariance matrix ' u ~N(0,S) ' set parameters !n = 2 ' number of variables !t = 100 ' number of random !n-pairs sym(!n,!n) S S.fill 1,-.2,3 matrix A = @cholesky(S) matrix(!n,!t) e nrnd(e) matrix u = @transpose(A*e) ' if you need to move u into workfile series you ' can use the command MTOS

Re: normal bivariate random generator

Posted: Fri Nov 14, 2008 5:22 am
by startz

Code: Select all

nrnd(e)
Is this use of the command nrnd documented somewhere?

Re: normal bivariate random generator

Posted: Fri Nov 14, 2008 9:03 am
by EViews Gareth
Possibly not. Its just a quick way to fill a matrix with (normal) random numbers