RANDGEN Call |
The RANDGEN subroutine generates random numbers from a specified distribution.
The input arguments to the RANDGEN subroutine are as follows:
is a matrix that is to be filled with random samples from the specified distribution.
is the name of the distribution that is to be sampled.
is a distribution shape parameter.
is a distribution shape parameter.
is a distribution shape parameter.
The RANDGEN subroutine generates random numbers by using the same numerical method as the RAND function in Base SAS software, with the efficiency optimized for matrices. You can initialize the random number stream that is used by RANDGEN by calling the RANDSEED subroutine. The result parameter should be preallocated to a size equal to the number of samples you want to generate. If result is not initialized, then it receives a single random sample.
The following distributions can be sampled.
The random sample is from the probability density function:
is in the range:
is the success probability, with range:
The random sample is from the probability density function:
is in the range:
and are shape parameters, with range: and
The random sample is from the probability density function:
is in the range:
is the success probability, with range:
specifies the number of independent trials, with range:
The random sample is from the probability density function:
is in the range:
The random sample is from the probability density function:
is in the range:
is degrees of freedom, with range:
The random sample is from the probability density function:
is in the range:
is an integer shape parameter, with range:
The random sample is from the probability density function:
is in the range:
The random sample is from the probability density function:
is in the range:
and are degrees of freedom, with range: and
The random sample is from the probability density function:
is in the range:
is a shape parameter:
The random sample is from the probability density function:
is in the range:
is the success probability, with range:
The random sample is from the probability density function:
is in the range:
is the population size, with range:
is the size of the category of interest, with range:
is the sample size, with range:
The random sample is from the probability density function:
is in the range:
The random sample is from the probability density function:
is in the range:
is the success probability with range:
is an integer number that counts the number of successes, with range:
The random sample is from the probability density function:
is in the range:
is the mean, with range: . This parameter is optional and defaults to 0.
is the standard deviation, with range: . This parameter is optional and defaults to 1.
The random sample is from the probability density function:
is in the range:
is the mean, with range
The random sample is from the probability density function:
is in the range:
is the degrees of freedom, with the range:
The random sample is from the probability density function:
where is a vector of probabilities, such that , and is the largest integer such that and
The random sample is from the probability density function:
is in the range:
is the horizontal location of the peak of the triangle, with range:
The random sample is from the probability density function:
is in the range:
The random sample is from the probability density function:
is in the range:
and are shape parameters, with range and
The following table describes how parameters of the RANDGEN call correspond to the distribution parameters.
Distribution |
distname |
parm1 |
parm2 |
parm3 |
---|---|---|---|---|
Bernoulli |
'BERNOULLI' |
|
||
Beta |
'BETA' |
|
|
|
Binomial |
'BINOMIAL' |
|
|
|
Cauchy |
'CAUCHY' |
|||
Chi-Square |
'CHISQUARE' |
|
||
Erlang |
'ERLANG' |
|
||
Exponential |
'EXPONENTIAL' |
|||
'F' |
|
|
||
Gamma |
'GAMMA' |
|
||
Geometric |
'GEOMETRIC' |
|
||
Hypergeometric |
'HYPERGEOMETRIC' |
|
|
|
Lognormal |
'LOGNORMAL' |
|||
Negative Binomial |
'NEGBINOMIAL' |
|
|
|
Normal |
'NORMAL' or 'GAUSSIAN' |
|
|
|
Poisson |
'POISSON' |
|
||
'T' |
|
|||
Table |
'TABLE' |
|
||
Triangle |
'TRIANGLE' or 'TRIANGULAR' |
|
||
Uniform |
'UNIFORM' |
|||
Weibull |
'WEIBULL' |
|
|
The distname argument can be in lowercase or uppercase, and you need to specify only enough letters to distinguish one distribution from the others, as shown by the following statements:
/* generate 10 samples from a Bernoulli distribution */ r = j(10, 1, .); /* allocate room for samples */ call randgen(r, "ber", 0.5);
Except for the normal distribution, you must specify the parameters listed for each of the preceding distributions. For the normal distribution, default values of and are used if no values are supplied.
The following example illustrates the use of the RANDGEN call:
call randseed(12345); /* get four random observations from each distribution */ x = j(1, 4, .); /* each row of m comes from a different distribution */ m = j(20, 4, .); call randgen(x, 'BERN', 0.75); m[ 1, ] = x; call randgen(x, 'BETA', 3, 0.1); m[ 2, ] = x; call randgen(x, 'BINOM', 0.75, 10); m[ 3, ] = x; call randgen(x, 'CAUCHY'); m[ 4, ] = x; call randgen(x, 'CHISQ', 22); m[ 5, ] = x; call randgen(x, 'ERLANG', 7); m[ 6, ] = x; call randgen(x, 'EXPO'); m[ 7, ] = x; call randgen(x, 'F', 12, 322); m[ 8, ] = x; call randgen(x, 'GAMMA', 7.25); m[ 9, ] = x; call randgen(x, 'GEOM', 0.02); m[10, ] = x; call randgen(x, 'HYPER', 10, 3, 5); m[11, ] = x; call randgen(x, 'LOGN'); m[12, ] = x; call randgen(x, 'NEGB', 0.8, 5); m[13, ] = x; call randgen(x, 'NORMAL'); m[14, ] = x; call randgen(x, 'POISSON', 6.1); m[15, ] = x; call randgen(x, 'T', 4); m[16, ] = x; p = {0.1 0.2 0.25 0.1 0.15 0.1 0.1}; call randgen(x, 'TABLE', p); m[17, ] = x; call randgen(x, 'TRIANGLE', 0.7); m[18, ] = x; call randgen(x, 'UNIFORM'); m[19, ] = x; call randgen(x, 'WEIB', 0.25, 2.1); m[20, ] = x; dist = {'BERN','BETA','BINOM','CAUCHY','CHISQ','ERLANG','EXPO', 'F','GAMMA','GEOM','HYPER','LOGN','NEGB','NORMAL', 'POISSON','T','TABLE','TRIANGLE','UNIFORM','WEIB'}; print m[rowname=dist];
m | ||||
---|---|---|---|---|
BERN | 1 | 0 | 1 | 0 |
BETA | 1 | 0.9999234 | 0.9842784 | 0.9997739 |
BINOM | 7 | 8 | 5 | 10 |
CAUCHY | -1.209834 | 3.9732282 | -0.048339 | -1.337284 |
CHISQ | 30.300691 | 20.653151 | 27.301922 | 26.878221 |
ERLANG | 10.636299 | 4.6455449 | 7.5284821 | 2.5558646 |
EXPO | 0.2449632 | 2.7656037 | 4.2254588 | 0.2866158 |
F | 0.7035829 | 1.2676112 | 0.9806787 | 1.4811389 |
GAMMA | 8.475216 | 8.8723256 | 8.2993617 | 8.0409742 |
GEOM | 109 | 4 | 33 | 30 |
HYPER | 1 | 1 | 2 | 1 |
LOGN | 0.7784513 | 0.9792472 | 0.6018993 | 0.3643607 |
NEGB | 3 | 2 | 0 | 2 |
NORMAL | 0.0053637 | 1.4026784 | -0.271338 | -0.416685 |
POISSON | 5 | 11 | 8 | 4 |
T | 1.3237918 | 0.0505162 | -0.660845 | -0.634447 |
TABLE | 2 | 3 | 2 | 3 |
TRIANGLE | 0.5270875 | 0.6909336 | 0.8607548 | 0.5450831 |
UNIFORM | 0.4064393 | 0.7464901 | 0.3463207 | 0.2615394 |
WEIB | 0.4183405 | 0.9981923 | 16.812803 | 0.0001131 |