BookmarkSubscribeRSS Feed
MarkGIP
Calcite | Level 5

Hi it's me again;)

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!!!

6 REPLIES 6
Rick_SAS
SAS Super FREQ

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.

MarkGIP
Calcite | Level 5

Hi Rick!

Once again I have to thank you for your quick response;)

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!!!!

MarkGIP
Calcite | Level 5

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!!!

Rick_SAS
SAS Super FREQ

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.

MarkGIP
Calcite | Level 5

Thank you so much, Rick!

I'm really thinking about getting your book;)

Rick_SAS
SAS Super FREQ

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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 6 replies
  • 1259 views
  • 0 likes
  • 2 in conversation