For questions regarding programming in the EViews programming language.
4 posts • Page 1 of 1
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 !
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
matrix A = @cholesky(S)
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.
Who is online
Users browsing this forum: Bing [Bot] and 5 guests