BookmarkSubscribeRSS Feed
aya123
Calcite | Level 5
Is the below code correct in order to generate 3 variables from multivariate normal distribution?

Proc iml;
Call randseed(1);
n= 50;
mean ={0 0 0};
corr= {1 0.7 0.6, 0.7 1 0.8, 0.6 0.8 1};
sigma= {2 3 4};
cov = corr # (sigma * t(sigma));
X = randnormal (n, mean, cov);
Print X;
3 REPLIES 3
Rick_SAS
SAS Super FREQ
No. You want
cov = corr # (t(sigma) * sigma);
which is a matrix, whereas sigma * t(sigma) is a scalar.

This is Method #3 in the following blog post, which describes how to convert between correlation and covariance matrices:
http://blogs.sas.com/iml/index.php?/archives/49-Converting-Between-Correlation-and-Covariance-Matric...
ayecon0325
Calcite | Level 5

Thanks Rick. I have a question about generating multivariate data. I just started learning simulation and I want to generate multivariate data that are correlated, say .60, but with a skewed distribution. How I thought about doing this is: first, generate the correlated data from a normal distribution (mean=0, and variance=1), and then second, transform it into a chi-square distribution (with df=3 that reflects a skewness=1.63 and a kurtosis=4). I know how to do the first step, but I'm stuck with the second step on how to do it. In the first place, is it even right to do the second step (i.e., transform it into a chi-square distribution?). If not, is there a better way to do it?

Thanks,

Ariel

Rick_SAS
SAS Super FREQ

Generating correlated MV data is a huge topic.  I discuss the best techniques (and provide SAS code to implement them) in Chapters 8, 9, and 16 of my book Simulating Data with SAS.

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
  • 3 replies
  • 1234 views
  • 1 like
  • 3 in conversation