1. Home
  2. GRANDOM procedure

GRANDOM procedure

Generates pseudo-random numbers from probability distributions (D.M. Roberts & P.W. Lane).

Options

DISTRIBUTION = string token Type of distribution required (beta, chisquare, exponential, F, gamma, logNormal, Normal, t, uniform, Weibull, expNormal, invNormal, skewNormal, Laplace, GEV, binomial, hypergeometric, Poisson); default Norm
NVALUES = scalar Number of values to generate; default 1
SEED = scalar Seed to start random number generation; default set by CALCULATE or continued from previous generation
MEAN = scalar Mean for distribution, except for Weibull or hypergeometric); default 0 for Normal distribution and 1 for Poisson and exponential, otherwise *
VARIANCE = scalar Variance for distribution, except for the Weibull or hypergeometric; must be positive; default *, except for Normal when default is 1
LOWER = scalar Lower bound for the uniform or beta distribution; default 0
UPPER = scalar Upper bound for the uniform or beta distribution; default 1
LOCATION = scalar Location parameter for the log-Normal, gamma or Weibull distribution; default 0
SCALE = scalar Scale parameter for the Weibull distribution; and exponentially modified Normal, must be positive; default 1
SHAPE = scalar Shape parameter for the Weibull, GEV and skewNormal distributions; must be positive; default 0 for GEV and 1 otherwise
ABETA = scalar First shape parameter for the beta distribution; must be positive; default 1
BBETA = scalar Second shape parameter for the beta distribution; must be positive; default 1
AGAMMA = scalar Location-scale parameter for the gamma distribution, must be positive, usually denoted by alpha or theta; default 1
BGAMMA = scalar Shape parameter for the gamma distribution, must be positive, usually denoted by beta or kappa; default 1
DF = scalar Number of degrees of freedom for the t or chi distribution, must be 1 or greater; default 1
DFNUMERATOR = scalar Number of degrees of freedom of the numerator for the F distribution, must be 1.0 or greater; default 1
DFDENOMINATOR = scalar Number of degrees of freedom of the denominator for the F distribution, must be 1.0 or greater; default 1
NBINOMIAL = scalar Number of binomial trials for the binomial distribution, must be positive; default 1
PROBABILITY = scalar probability of success for the binomial or hypergeometric distribution, must be positive and not greater than 1; default 0.5
NHYPERGEOMETRIC = scalar Number of elements for the hypergeometric distribution, must be positive; default 1
SSHYPERGEOMETRIC = scalar Sample size for the hypergeometric distribution, must be positive and less than NHYPERGEOMETRIC; default 1

Parameter

NUMBERS = scalar or variate The generated numbers are returned here; if the length of the supplied structure is defined, it must equal the setting of the NVALUES option

Description

GRANDOM generates pseudo-random numbers from the beta, chi-square, exponential, F, gamma, log-Normal, Normal, Student’s t, uniform, Weibull, exponentially modified Normal, inverse Normal, skew Normal, Laplace, generalized extreme value, binomial, hypergeometric and Poisson distributions.

The NUMBERS parameter of GRANDOM must be set to a scalar or variate to store the generated numbers. The NVALUES option can be set to specify how many values are required; if this is unset, a single value is generated. The SEED option can be set to initialize the random-number generator, hence giving identical results if the procedure is called again with the same options. If SEED is unset, generation will continue from the previous sequence in the program, or, if this is the first generation, the generator will be initialized by CALCULATE.

Most distributions can be specified by their mean and variance. In GRANDOM these are defined by the MEAN and VARIANCE options. For some distributions there are other defining parameters, which are often more convenient. These can be set by other options relevant to the distribution concerned.

Normal and Laplace distributions can be defined only by mean and variance; by default these are zero and one respectively, except for the inverse Normal where the mean must be positive, so there the default mean is 1.

For the exponential and Poisson distributions, either one of these is sufficient to define the distribution and, if neither is given, the mean is set to one. For the Poisson if both are specified they must be equal, while for the exponential the variance is the square of the mean. The chi-square distribution can be defined by any one of the DF, MEAN or VARIANCE options (the mean is equal to the degrees of freedom, and the variance to twice the degrees of freedom). Similarly, the Student’s t distribution can be defined by either the DF or the VARIANCE option; if MEAN is set, it must be zero. The F distribution can be generated by setting either the MEAN and VARIANCE options or the DFDENOMINATOR and DFNUMERATOR options.

The binomial distribution can be specified either by the MEAN and VARIANCE options (with MEAN greater than VARIANCE), or by the NBINOMIAL and PROBABILITY options. However, the hypergeometric distribution cannot be specified by MEAN and VARIANCE: instead the three options PROBABILITY, NHYPERGEOMETRIC and SSHYPERGEOMETRIC must be used.

The uniform distribution in the range (0,1) can be generated by setting the single option DIST=uniform. However, you can set the MEAN and VARIANCE options, or the LOWER and UPPER options, to get a uniform distribution in any other range. Similarly, the beta distribution is generated by default in the range (0,1), by setting the MEAN and VARIANCE options, or the ABETA and BBETA options: the mean is A/(A+B) and the variance is AB/((A+B+1)×(A+B)2). By setting the LOWER and UPPER options, the four-parameter beta distribution is generated, within the specified range.

The two-parameter gamma distribution can be generated by setting either the MEAN and VARIANCE options, or the AGAMMA and BGAMMA options. (The mean is AB and the variance is AB2: A is sometimes denoted by α or θ, and B by β or κ.) The three-parameter gamma can be generated by setting the LOCATION option, which simply has the effect of shifting a two-parameter gamma distribution. Similarly, the two- and three-parameter log-Normal distributions can be generated, though using the SCALE and SHAPE options rather than AGAMMA and BGAMMA. (If LOCATION is zero, the mean is sc × exp(sh2/2) and the variance is sc2 × exp(sh2) × (exp(sh2)-1; the square of the shape parameter is the variance of the associated Normal distribution, and the log(SCALE) is the mean.) The three-parameter Weibull is defined also by the LOCATION, SCALE and SHAPE options: it cannot be specified in terms of MEAN and VARIANCE. (The mean of the distribution is LOCATION+SCALE×G(1+1/SHAPE) and the variance is SCALE2×G(1+2/SHAPE)-(G(1+1/SHAPE))2), where G() is the gamma function.)

The skew Normal distribution is specified byhe MEAN and VARIANCE and SHAPE options. The distribution is skewed to the left if SHAPE is negative and to the right if it is positive. The exponentially modified Normal distribution is the sum of a Normal distribution with MEAN and VARIANCE and a exponential distribution with mean SCALE. The distribution is skewed to the right.

The generalized extreme value (GEV) distribution is specified by the MEAN, VARIANCE and SHAPE options. A SHAPE of zero gives a Gumbel distribution, a negative value gives a Fréchet distribution, and a positive value gives a Weibull distribution. These three distributions are also known as Type I, II and III extreme value distributions. The Extreme Value Theorem shows that the GEV distribution is the only possible limit distribution of properly normalized maxima of a sequence of independent and identically distributed random variables. The GEV distribution is often used as an approximation to model the maxima of long (finite) sequences of random variables.

Options: DISTRIBUTION, NVALUES, SEED, MEAN, VARIANCE, LOWER, UPPER, LOCATION, SCALE, SHAPE, ABETA, BBETA, AGAMMA, BGAMMA, DF, DFNUMERATOR, DFDENOMINATOR, NBINOMIAL, PROBABILITY, NHYPERGEOMETRIC, SSHYPERGEOMETRIC.
Parameter: NUMBERS.

Method

GRANDOM uses the “table look-up” method for the majority of the distributions, using the ED** functions in the CALCULATE directive. It uses the transformation method for the Weibull distribution, and the rejection method for the binomial, hypergeometric and Poisson distributions.

Action with RESTRICT

A variate that has been restricted will receive output from GRANDOM only in those units that are not excluded by the restriction. Values in the excluded units remain unchanged. Note that the NVALUES option must equal the full size of the variate.

See also

Directive: CALCULATE.
Procedures: GRCSR, GREJECTIONSAMPLE, GRLABEL, GRMNOMIAL, GRMULTINORMAL, GRTHIN, GRTORSHIFT, SAMPLE, SVSAMPLE.
Functions: GRBETA, GRBINOMIAL, GRCHISQUARE, GRF, GRGAMMA, GRHYPERGEOMETRIC, GRLOGNORMAL, GRNORMAL, GRPOISSON, GRSAMPLE, GRSELECT, GRT, GRUNIFORM.

Commands for: Calculations and manipulation.

Example

CAPTION   'GRANDOM example',\
          'Generate 250 values from the standard Normal distribution.';\
          STYLE=meta,plain
GRANDOM   [NVALUES=250; SEED=26354] Normal
" generate 250 gamma values, defining mean and variance "
GRANDOM   [DISTRIBUTION=gamma; MEAN=2.5; VARIANCE=5;\ 
          SEED=553616; NVALUES=250] Gamma1
" generate the same values, defining distribution parameters "
GRANDOM   [DISTRIBUTION=gamma; AGAMMA=1.25; BGAMMA=2;\ 
          SEED=553616; NVALUES=250] Gamma2
HISTOGRAM Normal,Gamma1,Gamma2
Updated on February 7, 2023

Was this article helpful?