## normal bivariate random generator

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Jason, EViews Moderator, EViews Matt

Philippe Rous
Posts: 8
Joined: Wed Oct 22, 2008 5:40 am

### normal bivariate random generator

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

Gene
EViews Expert
Posts: 20
Joined: Wed Sep 24, 2008 1:08 pm

### Re: normal bivariate random generator

Philippe Rous wrote: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-pairssym(!n,!n) SS.fill 1,-.2,3matrix A = @cholesky(S)matrix(!n,!t) enrnd(e)matrix u = @transpose(A*e)' if you need to move u into workfile series you ' can use the command MTOS`
Last edited by Gene on Fri Nov 14, 2008 3:34 pm, edited 1 time in total.

startz
Non-normality and collinearity are NOT problems!
Posts: 3399
Joined: Wed Sep 17, 2008 2:25 pm

### Re: normal bivariate random generator

Code: Select all

`nrnd(e)`

Is this use of the command nrnd documented somewhere?

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 11908
Joined: Tue Sep 16, 2008 5:38 pm

### Re: normal bivariate random generator

Possibly not. Its just a quick way to fill a matrix with (normal) random numbers