Statistical programming, matrix languages, and more

Loop RANDNORMAL

Reply
Contributor
Posts: 33

Loop RANDNORMAL

Hi it's me againSmiley Wink

I would like to loop the RANDNORMAL function using a random correlation matrix for a certain number of times. The results for each drawing should be added horizontally to the already existing ones.

Example:

RANDNORMAL is used in combination with a random correlation matrix to create a 1000x100 matrix M of standard normal distributed variables with a specific correlation structure. The goal is to repeat the procedure 20 times. The results of each run should be merged together. The result would be a 1000x20000 matrix. Each 1000x100 block should have a specific correlation structure (determined by the correlation matrix which changes in every run).

I hope you get the idea. I was wondering if you might know a way to loop the RANDNORMAL procedure in combination with a random correlation matrix....

THANKS A MILLION!!!

SAS Super FREQ
Posts: 3,227

Loop RANDNORMAL

What have you tried so far?

The hard part here is generating the random correlation matrix. Not every random matrix is a correlation matrix, and the algorithms for generating a correlation matrix are sometimes complicated. How hard it is depends on the "specific correlation structure" that you mention. Some simple structures that are sometimes used in simulations are the "intraclass" correlation structure, the MA(1) correlation structure, and the AR(1) correlation structure.

It looks like you are trying to sample from a multivariate normal distribution in 10 dimensions (since you have 10x10=100 columns).

Do you know how to write a function that generates a random 10x10 correlation matrix with the specific structure?

Depending on what you're trying to do, it might take days or weeks write this function.

Contributor
Posts: 33

Re: Loop RANDNORMAL

Hi Rick!

Once again I have to thank you for your quick responseSmiley Wink

To be honest, I have't spent much time on thinking about the generation of a random correlation matrix yet. However, since my last post I've figured out how to use macros to loop the entire process. So the random correlation matrix is next on my list.

Which of the structures you've mentioned would you prefer? So far I just thought about using uniformly distributed random numbers on the interval (-1,1), which I would use to create the correlation matrix.

I'm thankful for every comment...

THANK YOU!!!!

Contributor
Posts: 33

Re: Loop RANDNORMAL

Hi!

I know it's a little bit off topic but maybe you could help me..I spent some more time thinking about the correlation matrix. Do you know a way in IML to extract a correlation matrix from another (larger) correlation matrix? In detail, I want to select certain variables from a pool of variables. While the correlation matrix of the entire pool has been already calculated the correlation matrix of the selected variables should be extracted from the pool correlation matrix.

Example:

The pool consists of 10 variables. The corresponding 10x10 correlation matrix has been already calculated.

Now I select three variables of the pool. How can I extract the 3x3 correlation matrix from the pool correlation matrix via IML?

THANK YOU!!!

SAS Super FREQ
Posts: 3,227

Re: Loop RANDNORMAL

See pp. 31-32 of my book Statistical Programming with SAS/IML Software.Those pages are available as a FREE download.

To choose three random columns, use the RANCOMB function.

Contributor
Posts: 33

Re: Loop RANDNORMAL

Thank you so much, Rick!

I'm really thinking about getting your bookSmiley Wink

SAS Super FREQ
Posts: 3,227

Re: Loop RANDNORMAL

It makes the perfect Christmas gift, although it is too big to fit in a stocking. :-)

Post a Question
Discussion Stats
  • 6 replies
  • 342 views
  • 0 likes
  • 2 in conversation