normal bivariate random generator

For questions regarding programming in the EViews programming language.

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

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

normal bivariate random generator

Postby Philippe Rous » Thu Nov 13, 2008 10:02 am

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

Postby Gene » Thu Nov 13, 2008 10:28 pm

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
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: 3796
Joined: Wed Sep 17, 2008 2:25 pm

Re: normal bivariate random generator

Postby startz » Fri Nov 14, 2008 5:22 am

Code: Select all

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

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

Re: normal bivariate random generator

Postby EViews Gareth » Fri Nov 14, 2008 9:03 am

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


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests