BookmarkSubscribeRSS Feed
aya123
Calcite | Level 5
The following code is used to generate 50 vectors of size n and each vector is variable (E) having normal distribution with mean 0 and variance equals 1, so how can I generate this variable 50 times but when the variable (E) follows normal distribution with mean 0 and variance equals 4 ?

Do j=1 to 50;
E= normal(repeat(-1,n));
end;
2 REPLIES 2
nicolas_
Calcite | Level 5
You just multiply E by the square root of the variance, i.e. E=2#normal(repeat(-1,n));

A linear transformation aX+b of a normal variable X is again normally distributed with mean equal to a*mean(X) + b and variance equal to a^2*var(X)
Rick_SAS
SAS Super FREQ
You can use the RANDGEN call, which includes optional arguments for the mean and Std Dev. You first need to allocate a vector to store the data:
proc iml;
n=10;
E = j(n,1);
do i = 1 to 50;
call randgen(E, "Normal", 0, 4);
end;

You can also get all 50 variables at once. Each column of the following matrix contains a sample from N(0, 4).

E = j(n,50);
call randgen(E, "Normal", 0, 4);

For comments on generating random vectors efficiently, see
http://blogs.sas.com/iml/index.php?/archives/9-Efficient-Sampling.html

For a description of how to generate 50 variables that each have a different distribution, see
http://blogs.sas.com/iml/index.php?/archives/117-How-to-Sample-from-Independent-Normal-Distributions...

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

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