Statistical programming, matrix languages, and more

Generating multivariate normal data

Posts: 20

Generating multivariate normal data

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;
Posts: 3,628

Re: Generating multivariate normal data

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:
New Contributor
Posts: 2

Re: Generating multivariate normal data

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?



Posts: 3,628

Re: Generating multivariate normal data

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.

Ask a Question
Discussion stats
  • 3 replies
  • 1 like
  • 3 in conversation