Obsidian | Level 7

## simulation

Hello,

I am wondering how to simulate a gaussian vector with 3 random variable with proc IML in SAS, and to determine the covariance matrix of this vector.

If anyone could help,

Thank you

1 ACCEPTED SOLUTION

Accepted Solutions
SAS Super FREQ

## Re: simulation

From what you have said, I assume you want three independent Gaussian vectors. That is equivalent to a diagonal covariance matrix in the RANDNORMAL function. Based on your table, you would use

Mean = {0 0 0};  /* mean of population */

Cov = diag( {0.00264, 0.00286, 0.00590} );

6 REPLIES 6
Super User

## Re: simulation

calling @Rick_SAS

Super User

## Re: simulation

``````proc iml;
call randseed(1);
prob = {0.3,0.6,0.1};
NumTrials = 10;
N = 100;
x = RandMultinomial(N,NumTrials,prob);

SampleMean = mean(x);
SampleCov = cov(x);
print x,SampleMean, SampleCov ;
quit;``````
SAS Super FREQ

## Re: simulation

Use the RANDNORMAL function, as shown in the article "Sampling from the multivariate normal distribution."  If you want the three components to be independent, specify the identity matrix (I(3)) as a parameter. For correlated data, specify the population covariance matrix. You can use the COV function on the simulated data to estimate the population covariance.

BTW, KSharp's program simulates multinomial data, which is not the same as multivariate normal ("Gaussian").

Obsidian | Level 7

## Re: simulation

I have to put some mean and std that I have too in order to simulate them for each normal random variable. My parameters are the following :

How to use this parameters into your code?

Thanks a lot for the quick answer

Obsidian | Level 7

## Re: simulation

This is the only parameter that I have btw. I don't have the cov matrix. I just have the mean and the std for each cordonate of the vector.

SAS Super FREQ

## Re: simulation

From what you have said, I assume you want three independent Gaussian vectors. That is equivalent to a diagonal covariance matrix in the RANDNORMAL function. Based on your table, you would use

Mean = {0 0 0};  /* mean of population */

Cov = diag( {0.00264, 0.00286, 0.00590} );

Discussion stats
• 6 replies
• 1574 views
• 6 likes
• 3 in conversation