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 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 1812 views
  • 1 like
  • 3 in conversation